title: How to group LINQ query to dictionary<string, string>
body: <p>I have a simple model that I'm trying to group:</p>
  
  <pre><code>public class PracticeArea
  {
      [Key]
      public int PracticeAreaID { get; set; }
  
      public string Name { get; set; }
  
      public string Type { get; set; }
  
  }
  </code></pre>
  
  <p>I'd like to group by Type, how can I convert this:</p>
  
  <pre><code>var practiceAreas = (from c in db.PracticeAreas
                               select c).
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>public Dictionary&lt;string, string&gt; groupedPracticeAreas { get; set; }
  </code></pre>
  
  <p>I'm not sure how grouping works within Linq - I can run .ToGroup(),. but that doesn't give me my dictionary.</p>
  
  <p>I've tried:</p>
  
  <pre><code>practiceAreas = practiceAreas.ToDictionary(x =&gt; x.Type, x =&gt; x.Name);
  </code></pre>
  
  <p>But that gave me a cast error</p>