请问这个SQL语句如何转成Linq的写法?
SQL code
select a.ActivityTheme, u.username,c.CustomerName,i.ActivityClassName,a.ActivityAddress,a.ActivityTime
from tblActivity as a left join tblUser as u on a.UserId = u.UserId
left join tblCustomer as c on a.CustomerId = c.CustomerId
left join tblActivityClass as i on a.ActivityClassNo = i.ActivityClassNo
请指点,谢谢!
------解决方案--------------------
var query = from a in tblActivity
join u in tblUser on a.UserId equals u.UserId into tempUser
join c in tblCustomer on a.CustomerId equals c.CustomerId into tempCustomer
join i in tblActivityClass on a.ActivityClassNo equals i.ActivityClassNo into tempActivityClass
from tu in tempUser.DefaultIfEmpty()
from tc in tempCustomer.DefaultIfEmpty()
from ti in tempActivityClass.DefaultIfEmpty()
select new
{
a.ActivityTheme,
tu.username,
tc.CustomerName,
ti.ActivityClassName,
a.ActivityAddress,
a.ActivityTime
};
------解决方案--------------------from a in tblActivity
join u in tblUser on a.UserId equals u.UserId
join c in tblCustomer on a.CustomerId equals c.CustomerId
join i in tblActivityClass on a.ActivityClassNo equals i.ActivityClassNo
select new
{
a.ActivityTheme,
u.username,
c.CustomerName,
i.ActivityClassName,
a.ActivityAddress,
a.ActivityTime
};