将SQL转换为Linq - Where,in,Group By和Count count

时间:2013-09-25 17:46:24

标签: sql linq group-by having-clause

如何将此查询从SQL写入LINQ:

SELECT * FROM table
WHERE np in 
(
    SELECT np FROM table
    GROUP BY np 
    HAVING COUNT(np) > 1

1 个答案:

答案 0 :(得分:1)

这样的事情:

<Table>.GroupBy(x => x.np)
       .Where(x => x.Count() > 1)
       .SelectMany(x => x)