8
我知道的Linq的左联接是类似这样的:多个表左连接使用LINQ
var q=from e in db.Employes
join o in db.Orders on e equals o.Emoloyee into ords
from on in ords.DefautIfEmpty()
select new
{
e.FirstName,
e.LastName
};
那么如何对多个连接?这里是我的代码
var personalInfoQuery = from t in crnnsupContext.Tombstones
join p in crnnsupContext.ProvStates on t.ProvinceState equals p.ProvinceStateID
join n in crnnsupContext.NursingSchools on t.NursingSchool equals n.SchoolID
join i in crnnsupContext.InitialEducations on t.InitialEducation equals SqlFunctions.StringConvert((double)i.InitalEducationID, 1)
join g in crnnsupContext.tbl_GraduatedProvCountry on t.GradPovCountry equals g.id
where t.RegNumber == _username
select new CPersonalInfo
{
ProvState = p,
Tombstone = t,
NursingSchool = n,
InitialEducation = i,
GraduatedProvCountry = g,
};
每个连接表可以有“空”字段。可以帮助我,谢谢
非常感谢你! – pita
这样的陈述的问题是它的翻译。只有第一次连接将被转换为左连接,其他连接将会是内连接,并允许空值。 – Rufix
搜索了几个例子,这是我唯一的例子。 –