# linq 左连接 原理 有人解释一下原理吗？

0
[待解决问题]

public class As
{
public string a { get; set; }
public string b { get; set; }
public string c { get; set; }
}
public class Asd
{
public string a { get; set; }
public string b { get; set; }
public string c { get; set; }
}

``````        List<As> ass = new List<As> {
new As{a="1",b="b1",c="c1"},
new As{a="2",b="b2",c="c3"},
new As{a="3",b="b3",c="c3"},
new As{a="4",b="b4",c="c4"},
new As{a="5",b="b5",c="c5"},
};

List<Asd> asds = new List<Asd> {
new Asd{a="1",b="bb1",c="cc1"},
new Asd{a="2",b="bb2",c="cc2"},
new Asd{a="3",b="bb3",c="cc3"},
};``````

var sdsdssleft = from a in ass
join b in asds
on a.a equals b.a
into tmp
from c in tmp.DefaultIfEmpty()
select new
{
aa = a.a,
ab = a.b,
ac = a.c,
ba = c != null ? c.a : null,
bb = c != null ? c.b : null,
bc = c != null ? c.c : null,
};

var rr = ass.DefaultIfEmpty(); 代码可以直接这么写 rr ass 两者没差异

from c in tmp.DefaultIfEmpty() 中 tmp 既然为Asd的集合 返回的话 也是原数据 应该写了也相当于没写呀？

~雨落忧伤~ | 菜鸟二级 | 园豆：336

您需要登录以后才能回答，未注册用户请先注册