I have a linq query that I need to have doing left joins instead of inner joins. All of the examples I see show only 1 left join but when I tried it with 2 i couldn't get it right. So how would this change to use 2 left joins?
ruleSets = (from rs in db.RuleSets
join brs in db.BatchRuleSets on rs.ID equals brs.RuleSetID
join b in db.Batches on brs.BatchID equals b.id
where !clientId.HasValue || b.ClientID == clientId.Value
where !batchId.HasValue || brs.BatchID == batchId.Value
select new
{
rs.ID,
rs.Description,
rs.IsActive,
rs.CreatedDate,
rs.EffectiveDate,
rs.ExpirationDate,
BatchName = b.FileName,
b.ClientID
}).ToList().Select(x => new {
x.ID,
x.Description,
x.IsActive,
x.CreatedDate,
x.EffectiveDate,
x.ExpirationDate,
x.BatchName,
ClientName = GetClientName(x.ClientID)});
ToList(), then selecting again? First of all theToList()isn't really doing anything because the second select is turning it back to an IEnumerable<T> and second of all you could do your whole transform in the first select