please consider this 2 queries and their result:
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()
});
and it's result in GridView::

and the second query:
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() };
and it's result in GridView::

why Select(a => new) in first query show key column but select new does not show that?
try this
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() };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With