开发者

Linq to entity, using sql not in operator

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜