vb.net LINQ 选择新建
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22452118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 17:07:09 来源:igfitidea点击:
LINQ Select New
提问by undef.ms
I have DataTable that contains duplicate rows. I need take this rows. What I try to do
我有包含重复行的 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
but how i can to do Select New from this. I need
但是我该怎么做才能从中选择新的。我需要
Select New UserName = row("UserName"), UserId = row("UserId")
how i can do this in first query
我如何在第一个查询中做到这一点
采纳答案by Tim Schmelter
You can select an anonymous type
您可以选择匿名类型
Select New With { .UserName = row.Field(Of String)("Username"), .UserId = row.Field(Of Integer)("UserId") }
Integrated in the query, assuming that the combination of UserIdand UserNameis unique:
综合查询,假设的组合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

