ASP.NET Core & Web API (50 Qs)•Part 2: Entity Framework Core, Security & High-Performance Data (11 - 24)
What are Global Query Filters and how are they used for Soft Delete & Multi-Tenancy?
junior LevelFormsPerformanceSecurity & Auth
In Simple Words:
A query filter applied automatically to all queries for an entity type in OnModelCreating:
- Soft Delete:
modelBuilder.Entity<User>().HasQueryFilter(u => !u.IsDeleted); - Any
context.Users.ToList()automatically addsWHERE IsDeleted = 0. - To bypass when needed:
context.Users.IgnoreQueryFilters().ToList().