请考虑这两个查询及其结果:
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
没有显示?
答案 0 :(得分: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() };