Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert dataReader to Dictionary

I tried to use LINQ to convert one row to Dictionary (fieldName -> fieldValue)

return Enumerable.Range(0, reader.FieldCount)
                 .ToDictionary<string, object>(reader.GetName, reader.GetValue);

but I received error message:

Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable<int>' to 'System.Collections.Generic.IEnumerable<string>'

How to correct this?

like image 517
hellboy Avatar asked Aug 07 '12 09:08

hellboy


Video Answer


1 Answers

return Enumerable.Range(0, reader.FieldCount)
                 .ToDictionary(
                     i => reader.GetName(i),
                     i => reader.GetValue(i));
like image 189
Thomas Levesque Avatar answered Oct 05 '22 21:10

Thomas Levesque