开发者

LINQ to SQL - ToDictionary not supported - How do I pull results into memory?

开发者 https://www.devze.com 2023-01-01 01:31 出处:网络
var details= from row in databaseTable where row.id equals queryId select new { Dict = row.ToDiction开发者_如何学JAVAary(x => x.Name, x => x.Value),
  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.

0

精彩评论

暂无评论...
验证码 换一张
取 消