If I include the IgnoreQueryFilters method in one of the entities in the join I would expect other entities to keep the filter.
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.
EF Core version: 2.0.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 x64
IDE: Visual Studio 2017 15.6.6
@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:
C#
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.
Most helpful comment
@lcriscola one way to selectively suppress query filters, is to add flags on your derived DbContext. E.g. it would look something like this:
C# 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.