简体   繁体   English

如何在LINQ中编写“Not In”SQL查询?

[英]How to write a “Not In” SQL query in LINQ?

How would I translate the following SQL query in to a comparable LINQ query? 如何将以下SQL查询转换为可比较的LINQ查询?

select * from Dept 
where Id not in (
    Select Id 
    from Employee 
    where Salary > 100);

Try something like this: 尝试这样的事情:

var result = from d in Dept
             let expensiveEmployeeIds = (from e in Employee.Employees
                                       where e.Salary > 100
                                       select e.Id)
             where !expensiveEmployeeIds.Contains(d.Id)
             select d;

How about this? 这个怎么样?

var lowPaidEmps = from d in db.Dept 
                  join e in db.Employees on d.Id equals e.Id 
                  where e.Salary <= 100
                  select d;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM