开发者

How to write a "Not In" SQL query in LINQ?

开发者 https://www.devze.com 2022-12-30 09:24 出处:网络
How would I tra开发者_如何学编程nslate the following SQL query in to a comparable LINQ query?

How would I tra开发者_如何学编程nslate the following SQL query in to a comparable LINQ query?

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消