我有以下LINQ代码,我在stackoverflow上的一个问题中找到,我想用它来删除数据表中的重复行并留下索引最少的一行,这里是代码,我无法想象输出要在注释行中添加的代码
Dim duplicates = From row In GoogleResults.AsEnumerable()
Let seller = row.Field(Of String)("Seller")
Group row By seller Into DuplicateSellers = Group
Where DuplicateSellers.Count() > 1
Select DuplicateSellers
For Each DuplicateSellerRows In duplicates
For Each row In DuplicateSellerRows
'remove current row, but skip the first one
'row.Delete() will remove all rows but how can i keep the first one?
Next
Next
答案 0 :(得分:1)
您可以使用Skip()跳过每组重复项中的第一行:
For Each DuplicateSellerRows In duplicates
For Each row In DuplicateSellerRows.Skip(1)
row.Delete()
Next
Next