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
At the time of writing this feature request we can declare a QueryFilter expression using ModelBuilder APIs ( HasQueryFilter ) in the OnModelCreating method of DbContext, using instance fields which are injected by constructor (eg. TenantId).
This approach is quite cumbersome if we want to set filter expressions for an entity programmatically (lets say that I want a queryFilter to be applied only if user has a lower permissions role or I want this QueryFilter to restrict data using an IN clause, where IN clause arguments are retrived from the database or an external API maybe for every incoming request in an asp.net core middleware).
Currently the DbContext must declare a QueryFilter definition internally and not from outside
(eg dbContextInstance.Filter<Post>(expr filter)) so this leads to complex code and bloated DbContext class by fields and many other methods to calculate a dynamic QueryFilter .
This open-source library provides a simpler way to do that and works really well, but I would like to see this feature in EF Core without relaying on an external library (maybe you could opt for a separate package lets say Microsoft.EntityFrameworkCore.QueryFilters)
The approach I suggested might bring the following improvements:
Programmatic queryfilter declarations
Cleaner DbContext code (no instance fields holding QueryFilter arguments)
No extra constructor parameters for QueryFilter configuration
The text was updated successfully, but these errors were encountered:
@ZAP93 Thanks for posting; there are some interesting ideas here. I've added a line to #21459 to reference this issue, since this is where we are tracking general improvements to query filters.
At the time of writing this feature request we can declare a QueryFilter expression using ModelBuilder APIs (
HasQueryFilter
) in theOnModelCreating
method ofDbContext
, using instance fields which are injected by constructor (eg. TenantId).This approach is quite cumbersome if we want to set filter expressions for an entity programmatically (lets say that I want a queryFilter to be applied only if user has a lower permissions role or I want this QueryFilter to restrict data using an IN clause, where IN clause arguments are retrived from the database or an external API maybe for every incoming request in an asp.net core middleware).
Currently the DbContext must declare a QueryFilter definition internally and not from outside
(eg
dbContextInstance.Filter<Post>(expr filter)
) so this leads to complex code and bloated DbContext class by fields and many other methods to calculate a dynamic QueryFilter .This open-source library provides a simpler way to do that and works really well, but I would like to see this feature in EF Core without relaying on an external library (maybe you could opt for a separate package lets say Microsoft.EntityFrameworkCore.QueryFilters)
The approach I suggested might bring the following improvements:
The text was updated successfully, but these errors were encountered: