Linq 三表 left join 的实现
作者:互联网
目的实现:
select id,name,jname,cname from userinfo u left join job j on u.job=j.jid left join city c on u.city=c.cid 多表left join
代码如下:
var list = (from u in dc.userinfos
join j in dc.jobs on u.job equals j.jid into j_join
from x in j_join.DefaultIfEmpty()
join c in dc.cities on u.city equals c.cid into c_join
from v in c_join.DefaultIfEmpty()
select new
{
id=u.id,
name=u.name,
jname=x.jname,
cname=v.cname,
/*u1=u,x1=x,v1=v*///不要用对象的方式 因为对象可能为null那么对象.属性就会抛异常
}).ToList();
标签:city,join,dc,Linq,三表,jname,id,left 来源: https://www.cnblogs.com/simpleBlue3/p/10717487.html