[英]IGrouping <int, Customer> does not contain a definition for Points etc
I'm trying to group these, making the largest value of 'Points' displayed first but its giving me this error:我正在尝试对这些进行分组,首先显示“点”的最大值,但它给了我这个错误:
IGrouping <int, Customer>
does not contain a definition for Points, and no extension method Points accepting a first argument of typeIGrouping <int, Customer>
could be found.IGrouping <int, Customer>
不包含 Points 的定义,并且找不到接受IGrouping <int, Customer>
类型的第一个参数的扩展方法 Points。 Are you missing a using directive or an assembly reference?您是否缺少 using 指令或程序集引用?
Any help with this?有什么帮助吗? Thank you..
谢谢..
Customer result = db.Customer
.GroupBy(i => i.ID)
.OrderBy(i => i.Points)
.SelectMany(g => g);
//From Customer.cs
partial class Customer : Person
{
public int Points { get; set; }
}
//Note: ID is inherited from the abstract Person class
It seems to me that you just want something like this: 在我看来,您只想要这样的东西:
IEnumerable<Customer> result = db.Customer
.OrderByDescending(i => i.Points);
You only need GroupBy
if you have multiple items with the same key ( ID
). 仅当您有多个具有相同键(
ID
)的项目时,才需要GroupBy
。
I am not sure what you are trying to do with GroupBy
. 我不确定您要对
GroupBy
做什么。 However, the syntax should be like this - 但是,语法应如下所示-
Customer result = db.Customer
.GroupBy(i => i.ID)
.SelectMany(g => g)
.OrderBy(i => i.Points);
Just move OrderBy
after SelectMany
在
SelectMany
之后移动OrderBy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.