我有这个SQL查询来获取所有未分配给指定警车的警察名称。
SELECT policename
FROM police
LEFT OUTER JOIN policecar
ON police.policeid = policecar.policeid
AND carid = 1
WHERE policecar.policeid IS NULL
我想将该查询转换为 LINQ,但我很难转换 AND 和 WHERE 语句。请给我任何方向,谢谢。
试试这个:
var result =
from police in polices
join policecar in policecars.Where(x => x.carid == 1)
on police.policeId equals policecar.policeId into res
where !res.Any()
select police.policeName;