-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IgnoreQueryFilters in Joins disable filter for all entities #11853
Comments
@lcriscola IgnoreQueryFilters is currently a query-level operator and so affects all entities in the query. |
@lcriscola one way to selectively suppress query filters, is to add flags on your derived DbContext. E.g. it would look something like this: builder.Entity<Entity1>().HasQueryFilter(x => this.IgnoreFilterOnEntity1 || x.IsActive);
builder.Entity<Entity2>().HasQueryFilter(x => this.IgnoreFilterOnEntity2 || x.IsActive); Then you can set the flags to the right value before and after executing the query. |
Any comment on why this is considered not planned? |
One main difficulty in doing this, is that EF adds SQL JOINs - or correlated subqueries - in various situations when translating without an explicit LINQ Join operator. For example, in Overall, a better solution here is probably to implement named query filters (#8576), at which point you should be able to selectively disable specific filters (but still at the query level). |
If I include the IgnoreQueryFilters method in one of the entities in the join I would expect other entities to keep the filter.
Steps to reproduce
Lest assume the following code on the Context.OnModelCreating
and the following LINQ expression:
var q = from e1 in _context.Entity1.IgnoreQueryFilters ()
join e2 in _context.Entity2 on e1.ParentId equals e2.Id
select e1;
I would expect the generated sql to put a where clause on the Entity2. But no where clause is generated.
If no IgnoreQueryFilters is present, the generated sql includes a where clause of both tables.
Further technical details
EF Core version: 2.0.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 x64
IDE: Visual Studio 2017 15.6.6
The text was updated successfully, but these errors were encountered: