LINQ Group By to project into a non-anonymous type?

Posted by vikp on Stack Overflow See other posts from Stack Overflow or by vikp
Published on 2010-05-28T08:38:24Z Indexed on 2010/05/28 8:41 UTC
Read the original article Hit count: 239

Filed under:
|
|
|
|

Hi,

I have the following LINQ example:

var colorDistribution = 
    from product in ctx.Products
    group product by product.Color
    into productColors

    select
       new 
    {
       Color = productColors.Key,
       Count = productColors.Count()
    };

All this works and makes perfect sense.

What I'm trying to achieve is to group by into a strong type instead of anonymous type.

For example I have a ProductColour class and I would like to Group into a List<ProductColour>

Is this possible?

Thank you

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql