How to get the top 3 from each "by group" in LINQ?

I have a table that looks something like this:

Favorite color | Favorite food | Favorite dance | the date

Now I want to group by my favorite color and favorite dish. Then take the top 3 in each group, sorted by date (last). I just can't get it to work with LINQ.

+4
source share
1 answer

Like this:

from x in thingy group x by new { x.Color, x.Food } into g select new { g.Key.Color, g.Key.Food, Items = g.OrderByDescending(x => x.Date).Take(3) } 
+8
source

All Articles