You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.NET 10 is introducing LINQ LeftJoin and RightJoin operators, similar to the Join operator (see dotnet/runtime#110292). The new LeftJoin operator is intended to replace the traditional way of expressing a left join operation, as shown in the LINQ docs:
varquery=students.GroupJoin(departments,
student =>student.DepartmentID,
department =>department.ID,(student,departmentList)=>new{student,subgroup=departmentList}).SelectMany(
joinedSet =>joinedSet.subgroup.DefaultIfEmpty(),(student,department)=>new{student.student.FirstName,student.student.LastName,Department=department.Name});
This combination of GroupJoin/SelectMany/DefaultIfEmpty() is both comlex/verbose, and inefficient (see #110292 for some benchmark figures). In .NET 10, the above can be replaced with the following simpler (and more efficient) code:
varquery=students.LeftJoin(departments,
s =>s.DepartmentID,
d =>d.Id,(s,d)=>new{s.FirstName,s.LastName,DepartmentName=d.Name});
We can introduce an analyzer to pattern-match the GroupJoin/SelectMany/DefaultIfEmpty construct, and a codefix to transform it to the below LeftJoin construct.
In addition, dotnet/csharplang#8947 proposes a corresponding C# language change, adding left join (and right join) within LINQ query (comprehension) syntax:
fromstudentinstudentsleft join department in departments on student.DepartmentID equals department.IDselect new { student.Name, Department = department?.Name }
Again, this can replace the older pattern:
varquery=fromstudentinstudents
join departmentindepartments on student.DepartmentID equals department.ID into gjfromsubgroupingj.DefaultIfEmpty()selectnew{student.Name,Department=subgroup?.Name};
Assuming this makes sense, it's something I'd be happy to work on.
The text was updated successfully, but these errors were encountered:
.NET 10 is introducing LINQ LeftJoin and RightJoin operators, similar to the Join operator (see dotnet/runtime#110292). The new LeftJoin operator is intended to replace the traditional way of expressing a left join operation, as shown in the LINQ docs:
This combination of GroupJoin/SelectMany/DefaultIfEmpty() is both comlex/verbose, and inefficient (see #110292 for some benchmark figures). In .NET 10, the above can be replaced with the following simpler (and more efficient) code:
We can introduce an analyzer to pattern-match the GroupJoin/SelectMany/DefaultIfEmpty construct, and a codefix to transform it to the below LeftJoin construct.
In addition, dotnet/csharplang#8947 proposes a corresponding C# language change, adding
left join
(andright join
) within LINQ query (comprehension) syntax:Again, this can replace the older pattern:
Assuming this makes sense, it's something I'd be happy to work on.
The text was updated successfully, but these errors were encountered: