如何将此SQL转换为LINQ?

时间:2015-10-08 03:24:42

标签: sql linq

如何将以下SQL转换为Linq?

select ReqUserID, count(DepartmentID)
    from [ReqUsersDeptMat]
    where DepartmentID IN (93060,2175)
    group by ReqUserID
    having count(*) = 2 

1 个答案:

答案 0 :(得分:0)

试试这种方式

from item in ReqUsersDeptMat
group item by item.ReqUserID into groupedItems
let count = groupedItems.Count()
where count =2
select new { ReqUserID= groupedItems.Key, Num_Of_Departmentid = count };