Seems that a reposted question (
Joining 3 table in linq is it legal in C#[
^] ) contains information how Model and ProuctionDay are related, In other words
p.ProductionDate = m.CreatedDate
Based on that information, one simple way could be to split the operations to two parts. Something like
var dayResult = from w in db.Weeks
join p in db.ProductionDays on w.WeekId equals p.WeekId
select new {
w.Year,
w.WeekNum,
p.ProductionDate,
p.DayOfWeek
};
var actualResult = from item in dayResult
join m in db.Models on p.ProductionDate equals item.CreatedDate
where ---
select new {
item.Year,
item.WeekNum,
item.ProductionDate,
item.DayOfWeek,
m.Name,
m.Code,
m.InActive
};
Another option could be to try to combine the queries by creating intermediate results using into. Something like
var result = from w in db.Weeks
join p in db.ProductionDays on w.WeekId equals p.WeekId into res1
from item in res1
join m in db.Models on p.ProductionDate equals item.CreatedDate
where ---
select new {
w.Year,
w.WeekNum,
p.ProductionDate,
p.DayOfWeek,
m.Name,
m.Code,
m.InActive
};