Linq to Collections Group 通过取回原始实体
我使用以下代码对工具集合进行分组:
var filteredTools = from t in tools
group t by new { t.ModuleName,t.Number}
into g
select new { ModuleName = g.Key, Values = g };
工具是一个简单的集合,定义如下:
List<Tool> tools
执行分组后,我返回 3 行(从 40 行中),因此分组正在工作。行的键为 g.Key,Values 为分组条件。无论如何,有没有办法将其与原始工具联系起来。也许每个工具的密钥应该是唯一的,因此在执行分组后,我可以从工具集合中获取原始工具。
I am grouping a collection of tools using the following code:
var filteredTools = from t in tools
group t by new { t.ModuleName,t.Number}
into g
select new { ModuleName = g.Key, Values = g };
tools is a simple collection defined as follows:
List<Tool> tools
After grouping is performed I get 3 rows back (from 40 rows) so grouping is working. The rows have a key of g.Key and Values are the grouping conditions. Is there anyway to relate it back to the original tools. Maybe the key should be unique to each tool so after the grouping is performed I can fetch the original tool from the tools collection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这些工具仍然存在于每个组中:
说实话,您实际上并不需要在这里使用匿名类型进行选择。你可以使用:
Yes, the tools still exist within each group:
To be honest, you don't really need your anonymous type here for the select. You could use: