Description
While the new query filters feature is really cool, I think it is lacking additional flexibility for configuration + usage (enable / disable).
Let me use the example posted in your announcement blog: https://blogs.msdn.microsoft.com/dotnet/2017/05/12/announcing-ef-core-2-0-preview-1/
public class BloggingContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Post>()
.HasQueryFilter(p => !p.IsDeleted &&
p.TenantId == this.TenantId );
}
}
This example uses one filter for tenant id + isDeleted.
The only way to disable both filters is by using the following API:
Set<Post>().IgnoreQueryFilters()
Unfortunately there is no way to disable a specific part of the. It would make sense for example to disable only the IsDeleted filter
, while keeping the tenant filter
enabled.
This could be enabled by specifying multiple filters by key:
public class BloggingContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Post>()
.HasQueryFilter(p => !p.IsDeleted, key: "IsDeleted")
.HasQueryFilter(p => p.TenantId == this.TenantId, key: "Tenant");
}
}
Now one would have full flexibility to either disable all filters, or disable only specific filters:
Set<Post>().IgnoreQueryFilters("IsDeleted") // Only disables IsDeleted query filter, but keeps Tenant filter enabled
Set<Post>().IgnoreQueryFilters("TenantId") // Only disables TenantId query filter, but keeps is deleted filter enabled
Set<Post>().IgnoreQueryFilters() // disable all filters
Have you considered this scenario?