title: LINQ and the KeyValuePairs
body: <p>I'm trying to count items in a group. So I have this LINQ to Entities query:</p>
  
  <pre><code>var qry2 = from c in qry
             group c by c.Content.DownloadType into grouped
             select new KeyValuePair(grouped.Key,grouped.Count());
  </code></pre>
  
  <p>But it doesn't work because LINQ to Entities only accepts parameter initializers or parameterless constructors. So I created a simple class to envelop the KeyValuePair type:</p>
  
  <pre><code>public class ValueCount
  {
      public string Key { get; set; }
      public int Value { get; set; }
  
      public KeyValuePair&lt;string, int&gt; ToKeyValuePair()
      {
          return new KeyValuePair&lt;string, int&gt;(this.Key, this.Value);
      }
  }
  </code></pre>
  
  <p>And changed the query to:</p>
  
  <pre><code>var qry2 = from c in qry
             group c by c.Content.DownloadType into grouped
             select new ValueCount
             {
                 Key = grouped.Key,
                 Value = grouped.Count()
             }.ToKeyValuePair();
  </code></pre>
  
  <p>But still doesn't work. It says that it doesn't recognizes the method ToKeyValuePair()</p>
  
  <p>How can I collect KeyValuePairs from a LINQ to Entities query?</p>