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
搜索了幾個例子,這是我唯一的例子。 –