3

请考虑这两个查询及其结果:

var result = ent.tblCustomGroupBies
            .GroupBy(a => groupA.Contains(a.Group.Value) ? "A" :
                          groupB.Contains(a.Group.Value) ? "B" :
                          "N/a")
            .Select(a => new
            {
                KEY = a.Key,
                VALUE = a.Count()
            });

结果是GridView::

在此处输入图像描述

第二个查询:

 var result3 = from p in ent.tblCustomGroupBies
               group p by new { Criterion = groupA.Contains(p.Group.Value) ? "A" : 
                                            groupB.Contains(p.Group.Value) ? "B" : 
                                            "N/a" }
               into g
               select new { KEY = g.Key, VALUE = g.Count() };

结果是GridView::

在此处输入图像描述

为什么Select(a => new)在第一个查询中显示键列但select new不显示?

4

1 回答 1

2

试试这个

var result3 = from p in ent.tblCustomGroupBies
               group p by new { Criterion = groupA.Contains(p.Group.Value) ? "A" : 
                                            groupB.Contains(p.Group.Value) ? "B" : 
                                            "N/a" }
               into g
               select new { KEY = g.Key.Criterion, VALUE = g.Count() };
于 2012-11-08T06:27:42.433 回答