请考虑这 2 个查询及其结果:
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
没有显示? 最佳答案
试试这个
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() };
关于c# - "select new"和 "Select(a => new"的区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13283365/