LINQ:根据列值选择重复行
我试图在我的 DataGrid 中显示那些共享相同列值的行。
例如,对于具有相同姓氏的人,我尝试了以下方法:
dataGrid.ItemsSource = _dataContext.Addresses.GroupBy(a => a.SurName).Where(grp => grp.Count() > 1).Select(grp => grp.Key);
这似乎有效,因为我的 WPF DataGrid 包含此命令后的行...最终它只显示空行,因为没有列填充值。
或者我对具有同一城市的人进行了尝试:
dataGrid.ItemsSource = _dataContext.Addresses.GroupBy(a => a.City).Where(grp => grp.Count() > 1).Select(grp => grp.Key).Select(a => a);
有没有正确的方法可以做到这一点?
I'm trying to display those rows in my DataGrid, which share the same column-value.
For example, for Persons, who have the same Surname, I tried this:
dataGrid.ItemsSource = _dataContext.Addresses.GroupBy(a => a.SurName).Where(grp => grp.Count() > 1).Select(grp => grp.Key);
This works seemingly, as my WPF DataGrid contains rows after this command... Eventually it only displays empty rows, as no column is filled with a value.
Or I tried this with Persons, who have the same City:
dataGrid.ItemsSource = _dataContext.Addresses.GroupBy(a => a.City).Where(grp => grp.Count() > 1).Select(grp => grp.Key).Select(a => a);
Is there any proper way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只在示例中选择键:
我假设您要做的是选择整行:
比较名字和姓氏:
编辑:对于 L2E,您可以(我认为)使用匿名类型:
上面可以不正确 - 不是 100% 确定。
You are only selecting the key in your example:
What I assume you are trying to do is to select the whole row:
To compare first and last names:
EDIT: For L2E, you can (I think) use anonymous types:
The above could be incorrect- not 100% sure.