我正在尝试在两个表上执行左外连接,但我只想从第一个表中返回结果,其中第二个表没有记录(null)。
var agencies = from a in agencyList
join aa in joinTable
on a.AgencyId equals aa.AgencyId into joined
from aa in joined.DefaultIfEmpty()
where aa == null)
select a;
但是这并没有排除aa的非null值,并返回所有记录,就像'where aa == null'不在那里一样。
感谢任何帮助。感谢。
答案 0 :(得分:1)
怎么样:
var agencies = from a in agencyList
where (from aa in joinTable where aa.AgencyId == a.AgencyId select aa).Count() == 0
select a;