https://github.com/arnab-developer/ef-query-filter
EF Core query filter demo application.
https://github.com/arnab-developer/ef-query-filter
Last synced: 10 months ago
JSON representation
EF Core query filter demo application.
- Host: GitHub
- URL: https://github.com/arnab-developer/ef-query-filter
- Owner: Arnab-Developer
- License: mit
- Created: 2020-07-25T08:54:21.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-09T11:55:00.000Z (over 4 years ago)
- Last Synced: 2025-01-17T02:24:18.454Z (11 months ago)
- Language: C#
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EF core global query filter
What is global query filter? https://docs.microsoft.com/en-us/ef/core/querying/filters
This is a demo application to show the usage of Entity Framework Core's global query
filter. Global query filter can be mentioned in the `OnModelCreating` method of
`context` class.
```c#
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.SetQueryFilterOnAllEntities(s => s.SchoolId == SchoolId);
}
```
When this `context` class will be used then automatically filter will be applied before
returning result. Test has been written to show the output.
```c#
[Theory]
[InlineData(1)]
[InlineData(2)]
public void VerifyThatSchoolCanNotGetOtherSchoolsData(int schoolId)
{
// code here...
}
```