I know the Linq’s left join is similar like this:
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
};
then how about the multiple join? here is my code
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,
};
each joined table could have “null” field. can any help me, thanks
Multi join should look quite similar – it gets quite verbose, but I would give this a try.
You might need some null checking in the final
whereline too.There seems to be another way of doing outer joins as well but without having something to test it on I’m not even sure if it’s possible to use it in this case – check out the answer on this post if you’re interested:
outer join in linq