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

Embedded IgnoreQueryFilters() propagates to parent queries #13668

Closed
myrup opened this issue Oct 18, 2018 · 5 comments
Closed

Embedded IgnoreQueryFilters() propagates to parent queries #13668

myrup opened this issue Oct 18, 2018 · 5 comments

Comments

@myrup
Copy link

myrup commented Oct 18, 2018

I was a bit surprised to find embedded IgnoreQueryFilters() calls propagates to parent queries.

Steps to reproduce

var blogs = db.Blogs.Select(blog => new {
   blog.Id,
   Posts = db.Posts.IgnoreQueryFilters().Where(post => post.BlogId == blog.Id)
}).ToList();

In the above code I would expect IgnoreQueryFilters to only apply to posts and not also blogs.

Further technical details

EF Core version: 2.1.2
Database Provider: PostgreSql
Operating system: Mac OS X Mojave
IDE: VS Mac 7.6.9

@smitpatel
Copy link
Member

IgnoreQueryFilters applies to whole query. Just like AsTracking/AsNoTracking

@ajcvickers
Copy link
Member

@divega to follow up.

@ajcvickers
Copy link
Member

See also #10275 and #8576

@divega
Copy link
Contributor

divega commented Oct 22, 2018

@myrup one pattern you may consider using to have finer control of what filters are applied in a specific query execution is to introduce flags to shortcircuit spcific filters. The flags can be properties or fields on the DbContext. Your filters would look something like this:

modelBuilder.Entity<Blog>().HasQueryFilter(b => BlogFilterDisabled || b.Tenant == TenantId);
modelBuilder.Entity<Post>().HasQueryFilter(p => PostFilterDisabled || !p.IsDeleted);

Note that the flags will result in an additional Boolean parameters sent to the server for each query execution.

@myrup
Copy link
Author

myrup commented Oct 24, 2018

@ajcvickers @divega I can absolutely work around it. I am just looking at the example code and think that it is very counterintuitive (not C# like) that the filter is applied globally instead of on the collection the method call is on.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants