Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Last active July 23, 2021 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/10c2dc7a9047bfa5a9a9f3cfe92d8302 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/10c2dc7a9047bfa5a9a9f3cfe92d8302 to your computer and use it in GitHub Desktop.
.NET - Entity Framework Core - Global Query Filters Demo
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