我有包含重复行的DataTable。 我需要拿这行。 我尝试做什么
Dim dups1 = From row In objDataSet.Tables(0).AsEnumerable() _
Let UserId = row.Field(Of Integer)("UserId") _
Group row By UserId Into grp = Group _
Where (grp.Count() = 2) _
Select grp
但我该如何做从这里选择新的。我需要
Select New UserName = row("UserName"), UserId = row("UserId")
我如何在第一次查询中执行此操作
答案 0 :(得分:3)
您可以选择匿名类型
Select New With { .UserName = row.Field(Of String)("Username"), .UserId = row.Field(Of Integer)("UserId") }
集成在查询中,假设UserId
和UserName
的组合是唯一的:
Dim dups1 = From row In objDataSet.Tables(0).AsEnumerable()
Group row By UserCols = New With {
Key .UserId = row.Field(Of Integer)("UserId"),
Key .UserName = row.Field(Of String)("Username")
} Into Group
Where Group.Count() > 1
Select UserCols