假设我有一个这样的左外部联接:
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 }
如何使用扩展方法表达相同的任务?例如
Foo.GroupJoin(Bar, f => f.Foo_Id, b => b.Foo_Id, (f,b) => ???) .Select(???)
对于一个(左外)加入一个表的Bar一个表Foo上Foo.Foo_Id = Bar.Foo_Id在lambda符号:
Bar
Foo
Foo.Foo_Id = Bar.Foo_Id
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});