gpt4 book ai didi

vb.net - LINQ 选择新建

转载 作者:行者123 更新时间:2023-12-02 06:29:43 28 4
gpt4 key购买 nike

我的数据表包含重复的行。我需要采取这一行。我尝试做什么

 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")

我如何在第一个查询中做到这一点

最佳答案

您可以选择匿名类型

Select New With { .UserName = row.Field(Of String)("Username"), .UserId = row.Field(Of Integer)("UserId") }

集成在查询中,假设UserIdUserName的组合是唯一的:

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

关于vb.net - LINQ 选择新建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22452118/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com