title: Select top n rows in each group in EntityFramework
body: <p>I'm trying to fetch recent contents of each type, currently I'm using something similar to the following code to fetch n records for each type</p>
  
  <pre><code>int n = 10;
  var contents = Entities.OrderByDescending(i =&gt; i.Date);
  
  IQueryable&lt;Content&gt; query = null;
  for (int i = 1; i&lt;=5; i++)
  {
      if (query == null)
      {
          query = contents.Where(c =&gt; c.ContentTypeIndex == i).Take(n);
      }
      else
      {
          query = query.Concat(contents.Where(c =&gt; c.ContentTypeIndex == i).Take(n));
      }
  }
  </code></pre>
  
  <p>One other solution can be creating an SP, but is it possible to do it by grouping in EF? If not, any cleaner solution?</p>