Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translation of Projectable property fails

See original GitHub issue


What can be wrong in my code if translation of this simple projectable property fails (version is the latest 2.2.0, platform is .NET 6 with EF Core 6)?

query: var q2 = context.Students.Where(x => x.IsPaid);

Exception message when translate this query using q2.ToQueryString(): The LINQ expression ‘DbSet<Student>() .Where(s => !(s.IsDeleted)) .Where(s => s.IsPaid)’ could not be translated. Additional information: Translation of member ‘IsPaid’ on entity type ‘Student’ failed. This commonly occurs when the specified member is unmapped. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to ‘AsEnumerable’, ‘AsAsyncEnumerable’, ‘ToList’, or ‘ToListAsync’.

Student class has some real properties and also this one in a partial class: [Projectable] public bool IsPaid => PaymentMethod == 1;

Configuration of dbcontext:

       .ConfigureWarnings(x => x.Ignore(SqlServerEventId.SavepointsDisabledBecauseOfMARS)) //
       .UseProjectables(o => o.CompatibilityMode(EntityFrameworkCore.Projectables.Infrastructure.CompatibilityMode.Full)), ServiceLifetime.Scoped); 

Content of generated file:

using AB.KELLO.TANK2.Features.Infrastructure.Database.Interfaces;
using EntityFrameworkCore.Projectables;
using AB.KELLO.TANK2.Features.Domain.Entities;

namespace EntityFrameworkCore.Projectables.Generated
#nullable disable
    public static class AB_KELLO_TANK2_Features_Domain_Entities_Student_IsPaid
        public static System.Linq.Expressions.Expression<System.Func<global::AB.KELLO.TANK2.Features.Domain.Entities.Student, bool>> Expression()
            return (global::AB.KELLO.TANK2.Features.Domain.Entities.Student @this) => 
                @this.PaymentMethod == 1;

Query filter is used, that causes this part of the query: .Where(s => !(s.IsDeleted))

Context is prepared for using Projectables (UseProjectables() is called) , attribute is used on property…

Do you have any idea what is wrong here?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

beercsabacommented, May 2, 2022


If we use the given values (“Student” and “AB_KELLO_TANK2_Features_Domain_Entities_Student_IsPaid”) this query will fail always.

Full name of a type contains the name of the namespace also.

The namespace of the generated class is EntityFrameworkCore.Projectables.Generated (from the generated file).

You may rewrite the Where part of the query llike this: .Where (x => x.Namespace == "EntityFrameworkCore.Projectables.Generated" && x.Name == generatedContainingTypeName )

In this way the method named Expression() will be the result of the query.

Maybe it helps…

koenbeukcommented, Jun 3, 2023

Going to close this as the issue has become stale, feel free to reopen if this is still an issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

correct way of animating `Translation` of `UIElement ...
i have the following simple snippet which i expect to render an animated change of translation of a UIElement.
Read more >
EF6 include collection subquery of images is failing me
InvalidOperationException : 'Unable to translate a collection subquery in a projection since either parent or the subquery doesn't project ...
Read more >
Computed Properties and Entity Framework - Dave Glick
In the first case we're trying to use a computed property within a predicate, but Entity Framework doesn't know how to convert AccountValue...
Read more >
New riddle of induction
The new problem of induction becomes one of distinguishing projectible predicates such as green and blue from non-projectible predicates such as grue and...
Read more >
Re: Calculate a Property Value Based on Values from a ...
Hi Alex,. How does this interceptor solves calculated properties problem? Calculated properties have nothing to do with MARS, they are related ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found