<p>How do I properly convert two columns from SQL (2008) using Linq into a <code>Dictionary</code> (for caching)?</p>
<p>I currently loop through the <code>IQueryable</code> b/c I can't get the <code>ToDictionary</code> method to work. Any ideas?
This works:</p>
<pre><code>var query = from p in db.Table
            select p;

Dictionary&lt;string, string&gt; dic = new Dictionary&lt;string, string&gt;();

foreach (var p in query)
{
    dic.Add(sub.Key, sub.Value);
}
</code></pre>
<p>What I'd really like to do is something like this, which doesn't seem to work:</p>
<pre><code>var dic = (from p in db.Table
             select new {p.Key, p.Value })
            .ToDictionary&lt;string, string&gt;(p =&gt; p.Key);
</code></pre>
<p>But I get this error:</p>
<blockquote>
<p>Cannot convert from 'System.Linq.IQueryable&lt;AnonymousType#1&gt;' to
'System.Collections.Generic.IEnumerable'</p>
</blockquote>

```
```
var dictionary = db
    .Table
    .Select(p => new { p.Key, p.Value })
    .AsEnumerable()
    .ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
;
```
```