How should I structure a Linq query to return a List or Ienumerable of the most popular Tags in my db (I am using EF4.1 by the way).
Currently I have:
var tagsListing = db.Tags
.GroupBy(q => q.Name)
.OrderByDescending(gp => gp.Count())
.Take(5)
.Select();
I think I am part of the way there, but I am unsure of how to structure the Select statement…
Assuming you want the name and the count, just:
EDIT: If you want the complete tags as well, you could use:
which would give you a sequence of groups of tags, all with the same name within a group. Or you might only want the first tag within each group, e.g.
It’s not clear what a Tag consists of, or what exactly you want in the results.