title: LINQ - convert group to array
body: <p>I have a problem displaying most popular tags from database in view. I'm not sure about this question title so if someone has a better one please do rename it.</p>
  
  <h2>Scenario</h2>
  
  <p>I need to show recent posts, recent galleries and most popular tags on my index page. I decided to use tuples for this and it worked fine until I tried to show most popular tags.</p>
  
  <h2>Error</h2>
  
  <blockquote>
    <p>The model item passed into the dictionary is of type
    'System.Tuple<code>3[photoBlog.Models.Gallery[],photoBlog.Models.Post[],System.Linq.IGrouping</code>2[System.Int32,photoBlog.Models.PostTag][]]',
    but this dictionary requires a model item of type
    'System.Tuple`3[photoBlog.Models.Gallery[],photoBlog.Models.Post[],photoBlog.Models.PostTag[]]'.</p>
  </blockquote>
  
  <p>As you can see it gives my view wrong object type. I want expect it to be an array, but it gives me some kind of <code>System.Linq.Grouping</code> item.</p>
  
  <h2>Code</h2>
  
  <p>As you can see I convert it into array in my controller.</p>
  
  <pre><code>public ActionResult Index()
  {
      photoBlogModelDataContext _db = new photoBlogModelDataContext();
      var posts = _db.Posts.OrderByDescending(x =&gt; x.DateTime).Take(4).ToArray();
      var galleries = _db.Galleries.OrderByDescending(x =&gt; x.ID).Take(4).ToArray();
      var posttags = _db.PostTags.GroupBy(x =&gt; x.TagID).OrderBy(x =&gt; x.Count()).Take(4).ToArray();
      return View(Tuple.Create(galleries, posts, posttags));
  }
  </code></pre>
  
  <p>My view is straight forward, note that this did work until I tried to add most popular tags.</p>
  
  <pre><code>@model Tuple&lt;photoBlog.Models.Gallery[], photoBlog.Models.Post[], photoBlog.Models.PostTag[]&gt;
  @foreach (var tag in Model.Item3)
  { 
      @tag.Tag.Name
  }
  </code></pre>