Linq左连接
提问
如何Linq左连接
回答
注意
- into
- 推荐返回匿名类型
var query =
from person in people
join pet in pets on person equals pet.Owner into gj
from subpet in gj.DefaultIfEmpty()
select new
{
person.FirstName,
PetName = subpet?.Name ?? string.Empty
};
参考
https://learn.microsoft.com/zh-cn/dotnet/csharp/linq/perform-left-outer-joins