Hi All,
Following on from this question:
I have a table called Domains
, it has two columns:
DomainID int
DomainName varchar(250)
I want to return a Dictionary<int, string>
. When I try either of the following LINQ to SQL code:
Dictionary<int, string> dict =
dbc
.Domains
.Select(d => new {d.DomainID, d.DomainName})
.AsEnumerable()
.ToDictionary<int, string>(k => k.DomainID, k => k.DomainName);
or
Dictionary<int, string> dict =
(from d in dbc.Domains
select new { d.DomainID, d.DomainName })
.AsEnumerable()
.ToDictionary<int, string>(k => k.DomainID, k => k.DomainName);
I get the following compile error:
Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<AnonymousType#1>' to 'System.Collections.Generic.IEnumerable<int>'
The scenario here seems the same as q245168 and should work, am I missing something obvious?
Cheers
Kev