Named Query Filters in EF 10 (multiple query filters per entity)
EF 10 introduces named query filters, allowing multiple filters on a single entity and letting you selectively disable specific filters without turning off all query filters. This article explains how the feature works, shows practical examples for combining soft deletion and multi-tenancy...
C#:
public static class OrderFilters
{
public const string SoftDelete = nameof(SoftDelete);
public const string Tenant = nameof(Tenant);
}
modelBuilder.Entity<Order>()
.HasQueryFilter(OrderFilters.SoftDelete, order => !order.IsDeleted)
.HasQueryFilter(OrderFilters.Tenant, order => order.TenantId == tenantId);
// Later in your query
var allOrders = await context.Orders.IgnoreQueryFilters([OrderFilters.SoftDelete]).ToListAsync();
Bruh, I'm excited, query filters are pretty useful, and having more complex ones could be pretty handy.