我正在使用ADO.NET查询来选择位置为x,y或z且在主管下工作的所有员工的员工ID。
这是我正在使用的查询:
SELECT e.Employee_OID
FROM Employee e
WHERE EXISTS (SELECT 1
FROM Employee e1
WHERE e.Employee_OID = e1.Supervisor_OID
AND e1.Active_f = 'A')
AND e.Location_OID IN (123, 22)
AND e.Active_f = 'A'
我想将其转换为LINQ表达式,我是LINQ和EF的初学者,有人可以指导我将其写入LINQ吗?
这是我到目前为止所做的:
var supervisors = (from employee in Employee
where employee.location_OID == "???" //I have ID's in a list here
select employee.Employee_OID).Any();
答案 0 :(得分:4)
如果您使用的是EF 4.0或更高版本,则可以使用Contains()
检查项目是否在列表中:
where yourList.Contains(employee.location_OID)
exists
子查询可以使用Any()
:
where employee.Any(e1 => e.Employee_OID == e1.Supervisor_OID &&
e1.Active_f == "A")