[英]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.