I am trying to convert MySQL query to LINQ using LINQPad
MySQL Query
Select m.Id
from monthly as m
left join party as p on p.Id = m.PartyId
left join partymap as sp on sp.PositionId = m.PositionId and p.Id = sp.PartyId
LINQ Query
(
from m in monthly
join p in party on m.PartyId equals p.Id into part
from p in part.DefaultIfEmpty()
join sp in partymap on m.PositionId equals sp.PositionId into spPart
from sp in spPart.Where(sp => sp.PartyId == p.Id).DefaultIfEmpty()
select new
{
m.Id
}
)
Executing this query in LINQPad is giving below error
Message: Unknown column 'part.Id' in 'where clause'
What I am doing wrong here? The second condition p.Id = sp.PartyId
is added in where clause as it is. I tried switching the conditions. The error is at p.Id
. If I give any hardcode value in place of p.Id
, it works well.
Am I missing anything here?