Skip to content
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

Closed
lcriscola opened this issue Apr 30, 2018 · 4 comments
Closed

IgnoreQueryFilters in Joins disable filter for all entities #11853

lcriscola opened this issue Apr 30, 2018 · 4 comments
Labels
closed-no-further-action The issue is closed and no further action is planned.

Comments

@lcriscola
Copy link

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

		builder.Entity<Entity1>().HasQueryFilter(x => x.IsActive);
		builder.Entity<Entity2>().HasQueryFilter(x => x.IsActive);

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

@anpete
Copy link
Contributor

anpete commented Apr 30, 2018

@lcriscola IgnoreQueryFilters is currently a query-level operator and so affects all entities in the query.

@divega divega added the closed-no-further-action The issue is closed and no further action is planned. label Apr 30, 2018
@divega
Copy link
Contributor

divega commented May 1, 2018

@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.

@douglasg14b
Copy link

Any comment on why this is considered not planned?

@roji
Copy link
Member

roji commented Mar 19, 2024

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 context.Blogs.Where(b => b.Posts.Any()), a correlated subquery will be generated against the Posts table. But there's no real place for the user to place an IgnoreQueryFilters(), since Posts is just a List<Post> and not a DbSet (we can't introduce extension methods over List).

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Projects
None yet
Development

No branches or pull requests

6 participants