adsense

Wednesday, April 16, 2025

EF Core 10 Support for .NET 10 LeftJoin and RightJoin operators

 In earlier versions of EF Core, performing a LEFT JOIN in LINQ required a complex combination of SelectMany, GroupJoin, and DefaultIfEmpty.

With .NET 10, a new built-in LeftJoin method simplifies this process. It allows developers to write cleaner and more intuitive LINQ queries, and EF Core fully supports it in database queries.


Example:

var studentDepartments = context.Students

    .LeftJoin(

        inner: context.Departments,

        outerKeySelector: student => student.DepartmentID,

        innerKeySelector: department => department.ID,

        resultSelector: (student, department) => new

        {

            FirstName = student.FirstName,

            LastName = student.LastName,

            Department = department.Name ?? "[NONE]"

        });

Cheers
Samitha

No comments:

Post a Comment