C#Linq找到重复的行

use*_*675 3 c# linq

Name              City

Joe         Houston   
Jerry       London    
Alex        Houston   
Jerry       London    
Run Code Online (Sandbox Code Playgroud)

如何使用LINQ返回重复行

SQL

SELECT name, city, count(*)
FROM collection
GROUP BY name,city 
HAVING count(*) > 1
Run Code Online (Sandbox Code Playgroud)

我试了一下

var qry =
                from m in context.Collections
                group m by new { m.city, m.name } into grp
                select new { rp = grp.Count() > 2 };
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 14

你需要一个地方,而不是一个选择:

var qry =  from m in context.Collections
           group m by new { m.city, m.name } into grp
           where grp.Count() > 1
           select grp.Key;
Run Code Online (Sandbox Code Playgroud)