从Linq查询创建Dictionary <int,List <int >>

Num*_*man 1 c# linq-to-entities dictionary

我在数据库中有一个表如下...

ID(INT)    Values(VARCHAR(50))  
1          200,300  
2          100  
3          400,500  
Run Code Online (Sandbox Code Playgroud)

当我查询时,我需要在Dictionary>中获取这些数据

我到目前为止的代码是......

var x = (from o in Values select o).ToDictionary(o=>o.ID, p=>p.Values)

我希望将p.Values其转换为List,所以我还需要执行Convert.ToInt32()!
有任何想法吗?

dig*_*All 7

这应该工作:

var x = 
(from o in Values select o)
.ToDictionary(o => o.ID, 
              p => p.Values.Split(',')
                    .Select(x => Convert.ToInt32(x))
                    .ToList());
Run Code Online (Sandbox Code Playgroud)

.Select(x => Convert.ToInt32(x)) 可以转换为这样的方法组;-) .Select(Convert.ToInt32)