- Home
- .NET code examples
- Using global query filters in Entity Framework Core
Using global query filters in Entity Framework Core
Download this .NET sample project showing global query filters in Entity Framework Core. The examples include soft deleting records and multitenancy.
You can find out more about global query filters in Entity Framework Core, or watch the video:
Download the code example
You'll need to fill out the code example form. We will send you an email where you can download the code example.
Software
This is the software that will need to be installed onto your machine.
Visual Studio 2026. Version 18.0.0 or above. It will work with the free community version.
.NET 10 SDK. Version 10.0.0 or above.
Import the database
This application integrates with a SQL Server database. Inside the Database folder, there is RoundTheCode_EFQueryFilter.bacpac and RoundTheCode_EFQueryFilter.bak. Use either of these database backups to import the database to your local SQL Server database server.
The application
Inside Api/appsettings.Development.json, find ConnectionStrings > EFQueryFilterDbContext and point the connection string to your imported database.
Open up RoundTheCode.EFQueryFilter.slnx, and run the application. The Swagger documentation will load at https://localhost:7289/swagger with these endpoints:
/api/products- Uses query filters to get all products from theSiteIdset inConnectionStrings>EFQueryFilterDbContextthat aren't deleted./api/products/active- Ignores the multitenancy filter to get products from all sites that aren't deleted/api/products/{id}- Soft deletes a product by interceptingOnSaveChangesAsync. SetIdto 2 to try it.
Reset products data
To reset [dbo].[Products] , run ResetProducts.sql inside the Database folder against your database. This will revert [dbo].[Products] back to the original data.
Related code examples