GroupBy 然后采用 LINQ to Entities?
假设我有以下项目:
ID Category Name
1 Fruit Banana
2 Car Mescedes
3 Fruit Blackberry
4 Fruit Mango
5 Car Lexus
6 Fruit Melon
7 Car BMW
8 Car Toyota
我想将它们分组为 Category
并仅获取每个 Category
的前 3 个项目。是否可以?
我期望的输出:
ID Category Name
1 Fruit Banana
3 Fruit Blackberry
4 Fruit Mango
2 Car Mescedes
5 Car Lexus
7 Car BMW
任何帮助将不胜感激!
Let's say I have the following items:
ID Category Name
1 Fruit Banana
2 Car Mescedes
3 Fruit Blackberry
4 Fruit Mango
5 Car Lexus
6 Fruit Melon
7 Car BMW
8 Car Toyota
I want to group them into Category
and take only the first 3 items of each Category
. Is it possible?
I expected the output:
ID Category Name
1 Fruit Banana
3 Fruit Blackberry
4 Fruit Mango
2 Car Mescedes
5 Car Lexus
7 Car BMW
Any helps would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自头部且未测试:
From head and not tested:
假设您的列表集合被命名为categoryList..
实现您想要的结果的linq 查询是:
Lets say you list collection is named as categoryList..
The linq queries to achive what you want is: