Linq left join syntax correction needed
c#, linq
Solution
Use the `.DefaultIfEmpty` method on `r` to perform a left join:
var list = (from se in db.ServiceEntry
join r in db.RunLogEntry on se.RunLogEntryID equals r.ID into joinRunLogEntry
from r2 in joinRunLogEntry.DefaultIfEmpty()
join u in db.User on se.TechnicianID equals u.ID
join s in db.System1 on se.SystemID equals s.ID
where se.ClosedDate.HasValue == false
where se.ClosedDate.HasValue == false
&& se.Reconciled == false
orderby se.ID descending
select new ServiceSearchEntry()
{
ID = se.ID,
ServiceDateTime = se.ServiceDateTime,
Technician = u.FullName,
System = s.SystemFullName,
ReasonForFailure = se.ReasonForFailure,
RunDate = (r2 == null ? (DateTime?)null : r2.RunDate)
})
.Skip((page - 1) * PageSize);
Problem
I am having problems figuring out the `Linq` syntax for a left outer join within multiple joins. I want to do a left join on `RunLogEntry` Table so I get records which match from this table as well as all of the Service Entries. Can some one please correct my snytax? ``` var list = (from se in db.ServiceEntry join u in db.User on se.TechnicianID equals u.ID join s in db.System1 on se.SystemID equals s.ID join r in db.RunLogEntry on se.RunLogEntryID equals r.ID where se.ClosedDate.HasValue == false where se.ClosedDate.HasValue == false && se.Reconciled == false orderby se.ID descending select new ServiceSearchEntry() { ID = se.ID, ServiceDateTime = se.ServiceDateTime, Technician = u.FullName, System = s.SystemFullName, ReasonForFailure = se.ReasonForFailure, RunDate = r.RunDate }) .Skip((page - 1) * PageSize); ```