tags:

views:

85

answers:

2
  var details= from row in databaseTable
    where row.id equals queryId
    select new 
     {
       Dict = row.ToDictionary(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.

Thanks,

Logan

+1  A: 

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.

eKek0
+3  A: 
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>

Mike
Just beat me to it. The key here is that you need to first pull the data back, and then you translate it into a dictionary. It has to come back from the DB as raw data and then be modified to fit the OO perspective.
Stephan