var details= from row in databaseTable
where row.id equals queryId
select new
{
Dict = row.ToDiction开发者_如何学JAVAary(x => x.Name, x => x.Value),
};
When executing this LINQ to SQL I get the error;
System.NotSupportedException: The query operator 'ToDictionary' is not supported.
What I need to do is pull the rows into memory first but I'm not sure how. I tried calling ToList in various places but had no luck.
var fixTotaliserDetails = (from row in databaseTable
where row.id == queryId
select new
{
row.Name,
row.Value,
})
.ToDictionary(x=>x.Name, x=>x.Value);
This will work. I think you may have over-simplified your answer though, since in linq-to-sql an item in a table doesn't implement IEnumerable<T>
Did you try?
var fixTotaliserDetails = (from row in databaseTable
where row.id equals queryId
select name = x.Name, value = x.Value).ToDictionary(x => x.name);
and if you want to search by value, then change .ToDictionary(x => x.name);
by .ToDictionary(x => x.value);
.
Hope this helps.
精彩评论