【问题标题】:IGrouping <int, Customer> does not contain a definition for Points etcIGrouping <int, Customer> 不包含点等的定义
【发布时间】:2019-01-18 09:09:32
【问题描述】:

我正在尝试对这些进行分组,首先显示“点”的最大值,但它给了我这个错误:

IGrouping &lt;int, Customer&gt; 不包含 Points 的定义,并且找不到接受 IGrouping &lt;int, Customer&gt; 类型的第一个参数的扩展方法 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

【问题讨论】:

  • 请出示您的Customer 型号。请注意,每个分组将包含一个Key (i.ID) 到一个列表 客户 (IEnumerable&lt;Customer&gt;)。
  • 会的,等一下更新帖子。
  • 你想通过这个分组达到什么目的?或者,更好的是,您要整体实现什么目标?你能展示一些示例输入和输出吗?
  • 首先显示积分最高的客户。
  • Sum分了吗? (我假设您有多个 Customer 具有相同 ID 的对象,因为您正在对它们进行分组)

标签: c# linq


【解决方案1】:

在我看来你只是想要这样的东西:

IEnumerable<Customer> result = db.Customer
    .OrderByDescending(i => i.Points);

如果您有多个具有相同密钥的项目 (ID),则只需要 GroupBy

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多