LINQ to SQL - ToDictionary is not supported - how can I extract the results into memory?

var details= from row in databaseTable where row.id equals queryId select new { Dict = row.ToDictionary(x => x.Name, x => x.Value), }; 

When doing this LINQ to SQL, I get an error:

System.NotSupportedException: "ToDictionary" statement request is not supported.

What I need to do is first write the lines to memory, but I'm not sure how to do this. I tried calling ToList in different places, but no luck.

+4
source share
2 answers
 var fixTotaliserDetails = (from row in databaseTable where row.id == queryId select new { row.Name, row.Value, }) .ToDictionary(x=>x.Name, x=>x.Value); 

It will work. I think you might have simplified your answer too much, because since in linq-to-sql the element in the table does not implement IEnumerable<T>

+5
source

Have you tried

 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, change .ToDictionary(x => x.name); on .ToDictionary(x => x.value); .

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1310755/


All Articles