【问题标题】:SQL to LINQ - AND Statement in Left JoinSQL to LINQ - 左连接中的 AND 语句
【发布时间】:2013-10-09 14:37:39
【问题描述】:

我有这个 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 语句。请给我任何指导,谢谢。

【问题讨论】:

    标签: sql linq sql-to-linq-conversion


    【解决方案1】:

    试试这个:

    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;
    

    【讨论】:

    • 感谢您的回答。我想你不考虑carid = 1 还是我错过了什么?我想稍后将1 更改为任何carid
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    相关资源
    最近更新 更多