到目前为止,我有这个
var GetSetRows = from DataRow dr in MyTable.Rows
group dr by dr.Field<string>("SetNumber") into grp
from rows in grp
where grp.Count() > 1
select rows;
这可以返回SetNumber在另一行中的每一行。
如何将此修改为仅为每个具有Count&gt;的SetNumber返回1行? 1?
答案 0 :(得分:4)
使用Enumerable.First
:
var GetSetRows = from DataRow dr in MyTable.Rows
group dr by dr.Field<string>("SetNumber") into grp
where grp.Count() > 1
select grp.First();
答案 1 :(得分:1)
var GetSetRows = MyTable.Rows.GroupBy(x => x.Field<string>("SetNumber"))
.Where(g => g.Count() > 1)
.Select(g => g.First());
答案 2 :(得分:1)
var GetSetRows = MyTable.AsEnumerable()
.GroupBy(r => r.Field<string>("SetNumber"))
.Where(g => g.Count() > 1)
.Select(g => g.First());