You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we tried to use the projectable property with a global query filter on Entity<T>.HasQueryFilter(a=> a.projectableProperty), we got a The LINQ expression DbSet<T>().Where(n => n.projectableProperty == False) could not be translated.
Is this a bug or a some limitation?
Just tried to reproduce this and it indeed looks like a compatibility bug. I don't know yet how to fix this as the library is either extending IQueryCompiler or IQueryTranslationPreprocessorFactory (depending on compatibility mode) however it seems that query filters are a completely different beast. Fun fact: I just learned that dbContext.Set<Entity>().ToQueryString() does not expand query filters either.
Just stumbled on this limitation as well. :( We make heavy use of global filters (things like TenantId and UserId matched with data from session) and this library would be a perfect fit, if query filters would consider the projections, too.
A simple, but very easily understandable use case would be that we have Tenant, which has List of User, which has List of Portfolio.
I also have a system that enables queryfilters through interfaces. So what i want to do is to apply IHasTenant interface on Portfolio. That interface requires int TenantId { get; }. In Portfolio entity, i would like to write something like this:
[Projectable] public int TenantId => User.Tenant.Id;
I was able to solve this issue now based on the fix shown here, by calling the ExpandProjectables() on my own during the query filter registration. entityType.SetQueryFilter(queryFilter.ExpandProjectables() as LambdaExpression);
EDIT:
With the approach described above, I found that all the joins that would happen when projectable is evaluated, always happen even if i never select out any projectable properties. Seems like the ExpandProjectables() causes the joins happen no matter if the results are being used or not.
I am not sure if this behavior also happens with the implementation done in PR #130.
Activity
koenbeuk commentedon Aug 18, 2023
Just tried to reproduce this and it indeed looks like a compatibility bug. I don't know yet how to fix this as the library is either extending
IQueryCompilerorIQueryTranslationPreprocessorFactory(depending on compatibility mode) however it seems that query filters are a completely different beast. Fun fact: I just learned thatdbContext.Set<Entity>().ToQueryString()does not expand query filters either.Seramis commentedon Feb 21, 2025
Just stumbled on this limitation as well. :( We make heavy use of global filters (things like TenantId and UserId matched with data from session) and this library would be a perfect fit, if query filters would consider the projections, too.
A simple, but very easily understandable use case would be that we have
Tenant, which has List ofUser, which has List ofPortfolio.I also have a system that enables queryfilters through interfaces. So what i want to do is to apply
IHasTenantinterface onPortfolio. That interface requiresint TenantId { get; }. InPortfolioentity, i would like to write something like this:Handle global query filters (Fixes EFNext#81)
Handle global query filters (Fixes EFNext#81)
Merge pull request #130 from PhenX/feature/query-filters
Seramis commentedon Jun 19, 2025
I was able to solve this issue now based on the fix shown here, by calling the ExpandProjectables() on my own during the query filter registration.
entityType.SetQueryFilter(queryFilter.ExpandProjectables() as LambdaExpression);Thank you!
Any plans on the timing of next version of this library?
The main branch based test builds seem to be not accessible to the "outsiders". Otherwise i would use currently the latest build from here: https://github.com/koenbeuk/EntityFrameworkCore.Projectables/pkgs/nuget/EntityFrameworkCore.Projectables
EDIT:
With the approach described above, I found that all the joins that would happen when projectable is evaluated, always happen even if i never select out any projectable properties. Seems like the
ExpandProjectables()causes the joins happen no matter if the results are being used or not.I am not sure if this behavior also happens with the implementation done in PR #130.