C#Linq查找重复行 [英] C# Linq finding duplicate row
本文介绍了C#Linq查找重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
人员
Name City
Joe Houston
Jerry London
Alex Houston
Jerry London
如何使用LINQ之类的方法返回重复的行
How to return duplicate row using LINQ like
Sql
SELECT name, city, count(*)
FROM collection
GROUP BY name,city
HAVING count(*) > 1
我尝试了一些
var qry =
from m in context.Collections
group m by new { m.city, m.name } into grp
select new { rp = grp.Count() > 2 };
推荐答案
您需要一个位置,而不是一个选择:
You need a where, not a select:
var qry = from m in context.Collections
group m by new { m.city, m.name } into grp
where grp.Count() > 1
select grp.Key;
这篇关于C#Linq查找重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文