-1

我在stackoverflow上的一个问题中找到了以下LINQ代码,我想用它来删除数据表中的重复行并留下索引最少的行,这是代码,我无法弄清楚代码添加到注释行中

    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
4

1 回答 1

1

您可以使用Skip()跳过每组重复项中的第一行:

For Each DuplicateSellerRows In duplicates
    For Each row In DuplicateSellerRows.Skip(1)            
        row.Delete() 
    Next
Next
于 2012-09-20T01:56:11.493 回答