你如何执行左外部使用LINQ扩展方法联接 [英] How do you perform a left outer join using linq extension methods

查看:127
本文介绍了你如何执行左外部使用LINQ扩展方法联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个左外连接这样:

 从富˚F
在酒吧的f.Foo_Id加入b等于b.Foo_Id为G
从结果g.DefaultIfEmpty()
选择新{美孚= F,酒吧=结果}

我将如何前preSS使用扩展方法相同的任务?例如。

  Foo.GroupJoin(酒吧,F => f.Foo_Id,B => b.Foo_Id,(F,B)=> ???)
    。选择(???)


解决方案

  VAR QRY = Foo.GroupJoin(
          酒吧,
          富=> foo.Foo_Id,
          巴= GT; bar.Foo_Id,
          (X,Y)=>新富{= X,酒吧= Y})
    .SelectMany(
          X => x.Bars.DefaultIfEmpty(),
          (X,Y)=>新富{= x.Foo,酒吧= Y});

Assuming I have a left outer join as such:

from f in Foo
join b in Bar on f.Foo_Id equals b.Foo_Id into g
from result in g.DefaultIfEmpty()
select new { Foo = f, Bar = result }

How would I express the same task using extension methods? E.g.

Foo.GroupJoin(Bar, f => f.Foo_Id, b => b.Foo_Id, (f,b) => ???)
    .Select(???)

解决方案

var qry = Foo.GroupJoin(
          Bar, 
          foo => foo.Foo_Id,
          bar => bar.Foo_Id,
          (x,y) => new { Foo = x, Bars = y })
    .SelectMany(
          x => x.Bars.DefaultIfEmpty(),
          (x,y) => new { Foo=x.Foo, Bar=y});

这篇关于你如何执行左外部使用LINQ扩展方法联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆