Reputation: 3948
I have a table in database as follows...
ID(INT) Values(VARCHAR(50))
1 200,300
2 100
3 400,500
when I query, I need to get this data in a Dictionary>
The code I have so far is...
var x = (from o in Values
select o).ToDictionary(o=>o.ID, p=>p.Values)
I would like the p.Values
to be converted to a List so I also need to perform a Convert.ToInt32() possibly!
Any ideas?
Upvotes: 1
Views: 1416
Reputation: 57210
This should work:
var x =
(from o in Values select o)
.ToDictionary(o => o.ID,
p => p.Values.Split(',')
.Select(x => Convert.ToInt32(x))
.ToList());
.Select(x => Convert.ToInt32(x))
can be converted to a method group like this ;-) .Select(Convert.ToInt32)
Upvotes: 7