我有一个 linq-to-sql 查询,它可以分组和计数,结果最终出现在字典中。我想将字典映射到对象模型的属性。对象模型如下所示:
public class MyCountModel()
{
int CountSomeByte1 { get; set; }
int CountSomeByte2 { get; set; }
int CountSomeByte3 { get; set; }
int CountSomeByte4 { get; set; }
int CountSomeByte5 { get; set; }
int CountSomeByte6 { get; set; }
}
我想映射字典,以便查询像这样结束:
var TheQuery = MyDC.SomeTable
.Where(...)
.GroupBy(...)
.ToDictionary(x => x.Key, x=> x.Count()
.Select(m => new MyCountModel()
{
CountSomeByte1 = ..., // the value where Key is 1
CountSomeByte2 = ...., // the value where Key is 2
....
CountSomeByte6 = .... // the value where Key is 6
});
我怎么能写出这样的东西?感谢您的建议。