linq to sql left join 三表以查询
我现在有三个表
tbOne
tbTwo
tbThree
tbOne 有两个字段 tbOneId ,tbOneName
tbTwo 有三个字段 tbTwoId,tbTwoName, tbOneId,tbThreeId
tbThree 有两个字段 tbThreeId,tbThreeName
数据: 其中tbOne 表里面有数据,tbTwo无任何数据,tbThree有数据
我想实现如下功能 以下是我写的sql语句
select
us.tbOneName,ca.tbTwoName,u.tbThreeName
from tbOne as us
left join tbTwo as ca on us.tbOneId = ca.tbOneId
left join tbThree as u on ca.tbThreeId=u.tbThreeId
请问怎么样在linq to sql 里面实现
------解决方案--------------------
C# code
var query= from us in tbOne
join ca in tbTwo
on us.tbOneId equals ca.tbOneId
into temp
from ca in temp.DefaultIfEmpty()
join u in tbThree
on ca.tbThreeId equals u.tbThreeId
into temp1
from u in temp1.DefaultIfEmpty()
select new
{
us.tbOneName,
ca.tbTwoName,
u.tbThreeName
};