C# 带toDictionary的Linq查询

C# 带toDictionary的Linq查询,c#,asp.net,linq,entity-framework,C#,Asp.net,Linq,Entity Framework,我有以下linq查询 var temp = (from p in db.BEM_EVT_FULL where (p.date_reception > dt) group p by p.mc_object into g orderby g.Count() descending select new StringIn

我有以下linq查询

  var temp = (from p in db.BEM_EVT_FULL
                      where (p.date_reception > dt)
                      group p by p.mc_object into g
                      orderby g.Count() descending
                      select new StringIntType
                      {
                          str = g.Key,
                          nbr = g.Count()
                      }).Take(50).ToList();

我需要将Dictionary与int和string类型一起使用,而不是将结果强制转换为StringIntType。

您可以尝试以下方法:

var temp = (from p in db.BEM_EVT_FULL
            where (p.date_reception > dt)
            group p by p.mc_object into g
            orderby g.Count() descending
            select new
            {
                Key = g.Key,
                Value = g.Count()
            }).Take(50)
              .ToDictionary(x=>x.Key, y=>y.Value);

您可以尝试以下方法:

var temp = (from p in db.BEM_EVT_FULL
            where (p.date_reception > dt)
            group p by p.mc_object into g
            orderby g.Count() descending
            select new
            {
                Key = g.Key,
                Value = g.Count()
            }).Take(50)
              .ToDictionary(x=>x.Key, y=>y.Value);

这个问题似乎有一个答案:

基本上,使用ToDictionary代替ToList

.ToDictionary( t => t.Key, t => t.Value);

这个问题似乎有一个答案:

基本上,使用ToDictionary代替ToList

.ToDictionary( t => t.Key, t => t.Value);