Last active
July 23, 2021 20:52
-
-
Save manoj-choudhari-git/10c2dc7a9047bfa5a9a9f3cfe92d8302 to your computer and use it in GitHub Desktop.
.NET - Entity Framework Core - Global Query Filters Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
// Only Queries are shown below | |
// Rest of the methods are same as shown in previous snippet | |
static async Task DisplayStudentsByNationality(string nationality) | |
{ | |
using var context = BuildUniversityContext(); | |
var studentCollection = await context.Students | |
.Where(x => x.Nationality == nationality) | |
.ToListAsync(); | |
Console.WriteLine(); | |
Console.WriteLine($"Display {nationality} Students: "); | |
Display(studentCollection); | |
} | |
static async Task DisplayAllStudents() | |
{ | |
using var context = BuildUniversityContext(); | |
var studentCollection = await context.Students.ToListAsync(); ; | |
Console.WriteLine(); | |
Console.WriteLine("Display All Non-Deleted Students"); | |
Display(studentCollection); | |
} | |
static async Task DisplayDeletedStudents() | |
{ | |
using var context = BuildUniversityContext(); | |
var studentCollection = await context.Students | |
.IgnoreQueryFilters() // To ignore global filters | |
.Where(x=> x.IsDeleted).ToListAsync(); ; | |
Console.WriteLine(); | |
Console.WriteLine("Display Deleted Students"); | |
Display(studentCollection); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment