关于linq to entity Left join 的问题 select * from [table1] a
left join [table2] b on a.ID = b.ID
left join [table3] c on a.ID = c.ID
left join [table4] c on a.ID = c.ID
.....
...
如何转换成LinQ啊...
貌似用了Linqer也没用
------最佳解决方案-------------------- from c in table1
join p in table2 on c.ID equals p.PID into t1
from p in t1.DefaultIfEmpty()
join d in table3 on p.EID equals pi.PIID into t2
from d in t2.DefalutIfEmpty()
select c; ------其他解决方案--------------------
from c in table1
join p in table2 on c.ID equals p.PID
join d in table3 on p.EID equals pi.PIID
select new
{
c.ID, p.PID, pi.PIID
}
..我用这种方法结果是
base {System.SystemException} = {"到值类型“Guid”的强制转换失败,因为具体化值为 null。结果类型的泛型参数或查询必须使用可以为 null 的类型。"}
我的LINQ是这样写的
var result = (from a in table1
join b in table2 on a.a_guid equals b.b_guid into t1
from b in t1.DefaultIfEmpty()
join c in table3 on a.a_guid equals c.c_guid into t2
from c in t2.DefaultIfEmpty()
join e in table4 on a.a_userid equals e.e_userid into t3
from e in t3.DefaultIfEmpty()
orderby a.CreateWhen
select new {....});