I am trying to get my head around how to generate the equivalent of this LEFT JOIN in Linq. It contains a subquery which gets the lowest service_id for the person in that row being joined, and then also restricts on service_code = "N" in both the subquery and the join). I just cant seem to get it to work in Linq.
SQL:-
LEFT OUTER JOIN SERVICE ON person.id_person = SERVICE.id_person
AND SERVICE.id_service = (SELECT MIN(id_service) FROM SERVICE WHERE id_person = person.id_person AND service_code = 'N')
AND SERVICE.service_code = 'N'
NB: I know how to do the left join correctly (DefaultIfEmpty() etc). Its the subquery that is the problem. How do I squeeze that subquery into the .Where clause in Linq?