title: Group posts by year, then by month
body: <p>I need some help with LINQ-2-SQL in order to group some blog posts by a year and month.</p>
  
  <p>Basically, I have a collection of blog posts that have the following properties</p>
  
  <ul>
  <li>Id</li>
  <li>Title</li>
  <li>Date</li>
  </ul>
  
  <p>I want to be able to iterate through each year, then iterate through every month of that year, and finally, iterate through every blog post within that month. Something like </p>
  
  <ul>
  <li>2011
  <ul>
  <li>April <em>(show number of posts)</em>
  <ul>
  <li>Random Post 1 </li>
  <li>Random Post 2</li>
  </ul></li>
  <li>May <em>(show number of posts)</em>
  <ul>
  <li>Random Post 2 </li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p><strong>etc...</strong> </p>
  
  <p>Is there a way I can do this with a single LINQ query, using the group by clause?</p>
  
  <p><strong>Here's as far as I've got</strong></p>
  
  <pre><code>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() });
  </code></pre>