concept global query filter in category entity framework

appears as: global query filter
Entity Framework Core in Action, SE

This is an excerpt from Manning's book Entity Framework Core in Action, SE.

  • Add a global query filter via EF Core fluent configuration commands. The effect of this is to apply an extra Where filter to any access to the Books table.
  • Adding the global query filter to the DbSet<Book>Books property means adding a fluent configuration command to the application’s DbContext. Chapter 7 covers this configuration command, but it’s shown in bold in the following listing, so you have an idea of what’s going on.

    Listing 3.22 Adding a global query filter to the DbSet<Book>Books property
    public class EfCoreContext : DbContext
    {
        //… Other parts removed for clarity
     
        protected override void
            OnModelCreating(ModelBuilder modelBuilder)
        {                                                 
            //… other configration parts removed for clarity
     
            modelBuilder.Entity<Book>()                #A
                .HasQueryFilter(p => !p.SoftDeleted);  #A
        }
    }