开发者

Linq to entity, using sql not in operator

开发者 https://www.devze.com 2023-03-07 08:14 出处:网络
Hi How can I write the following sql query by linq Select * From Employee where EmployeeId not开发者_如何学Go in (Select EmployeeId in orders)

Hi How can I write the following sql query by linq

Select * From Employee where EmployeeId not开发者_如何学Go in (Select EmployeeId in orders)


You can try either this:

var query = from e in context.Employees
            let ids = context.Orders.Select(o => o.Employee.Id)
            where !ids.Contains(e.Id)
            select e;

or this:

var query = from e in context.Employees
            where !context.Orders.Any(o => o.Empolyee.Id == e.Id)
            select e;
0

精彩评论

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