日期:2014-05-20  浏览次数:20916 次

关于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
}


------其他解决方案--------------------
引用:
C# code123456789from c in table1join 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}


0. 0其实看得不是很懂..
[Table1]中的ID包含了其他所有表中的ID并且其他表中的ID是不相同的
这种情况下光是用join进行多表联合查不到数据...
------其他解决方案--------------------
引用:
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()
……

..我用这种方法结果是
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 {....});


------其他解决方案--------------------