[英]IGrouping <int, Customer> does not contain a definition for Points etc
我正在尝试对这些进行分组,首先显示“点”的最大值,但它给了我这个错误:
IGrouping <int, Customer>
不包含 Points 的定义,并且找不到接受IGrouping <int, Customer>
类型的第一个参数的扩展方法 Points。 您是否缺少 using 指令或程序集引用?
有什么帮助吗? 谢谢..
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
在我看来,您只想要这样的东西:
IEnumerable<Customer> result = db.Customer
.OrderByDescending(i => i.Points);
仅当您有多个具有相同键( ID
)的项目时,才需要GroupBy
。
我不确定您要对GroupBy
做什么。 但是,语法应如下所示-
Customer result = db.Customer
.GroupBy(i => i.ID)
.SelectMany(g => g)
.OrderBy(i => i.Points);
在SelectMany
之后移动OrderBy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.