我有这个数据表(RadkyData):
Name EAN PRICE
ITEM1 12345 10
ITEM2 5558 55
ITEM3 12345 44
我需要搜索具有重复值EAN的行。? (所有重复的EAN列表) 我有这段代码:
var polozkySum = RadkyData.AsEnumerable()
.Select(r => new
{
c2 = r.Field<string>("EAN")
})
.GroupBy(g => new { g.c2 })
.Select(x => new
{
col2 = x.Key.c2
});
请问您有什么想法吗?
答案 0 :(得分:1)
var rowsWithDupEAN = RadkyData.AsEnumerable()
.GroupBy(row => row.Field<string>("EAN"))
.Where(g => g.Count() > 1)
.SelectMany(g => g);
如果您不想要行但只需要此列值(如注释中所述):
var dupEanList = RadkyData.AsEnumerable()
.GroupBy(row => row.Field<string>("EAN"))
.Where(g => g.Count() > 1)
.Select(g => g.Key)
.ToList();
答案 1 :(得分:0)
您可以使用LINQ to DataTable。
var result = Radkydata.AsEnumerable()
.GroupBy(r => r.Field<string>("EAN"))
.Select(g => g.First())
.CopyToDataTable();