I need help with LINQ-2-SQL to group some blog posts by year and month.
Basically, I have a collection of blog posts that have the following properties
I want every month of this year to go through an iteration, then repeat every month of this year, and finally repeat every blog post for that month. Something like
- 2011
- April (show the number of posts)
- Random Article 1
- Random Article 2
- May (show the number of publications)
etc.
Is there a way to do this with a single LINQ query using a group by clause?
Here, as far as I know,
var groupedBlogPosts = (from p in blogPostsFiltered group p by new { month = p.Date.Month, year = p.Date.Year } into d select new { postDate = string.Format("{0}/{1}", d.Key.month, d.Key.year), postCount = d.Count() });
Marko
source share