LEFT OUTER JOIN in LINQ

后端 未结 22 3011
臣服心动
臣服心动 2020-11-21 04:49

How to perform left outer join in C# LINQ to objects without using join-on-equals-into clauses? Is there any way to do that with where clause? Corr

22条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-21 05:21

    Take a look at this example. This query should work:

    var leftFinal = from left in lefts
                    join right in rights on left equals right.Left into leftRights
                    from leftRight in leftRights.DefaultIfEmpty()
                    select new { LeftId = left.Id, RightId = left.Key==leftRight.Key ? leftRight.Id : 0 };
    

提交回复
热议问题