简体   繁体   中英

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 type IGrouping <int, Customer> could be found. Are you missing a using directive or an assembly reference?

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 ).

I am not sure what you are trying to do with 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM