...

/

Filtering and Sorting Sequences in LINQ

Filtering and Sorting Sequences in LINQ

Learn about filtering and sorting sequences of rows from tables using LINQ, and discover how to efficiently log the generated SQL statements for the queries.

Filtering and sorting

Let’s write statements to filter and sort sequences of rows from the tables:

Press + to interact

Step 1: In the LinqWithEFCore project, add a new class file name Program.Helpers.cs.

Step 2: In Program.Helpers.cs, define a partial Program class with a method to output a section title, as shown in the following code:

Press + to interact
partial class Program
{
static void SectionTitle(string title)
{
ConsoleColor previousColor = ForegroundColor;
ForegroundColor = ConsoleColor.DarkYellow;
WriteLine("*");
WriteLine($"* {title}");
WriteLine("*");
ForegroundColor = previousColor;
}
}

Step 3: In the LinqWithEFCore project, add a new class file named Program.Functions.cs. ...