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

posted @ 2023-03-23 14:28  喜爱糖葫芦  阅读(16)  评论(0编辑  收藏  举报