3

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::

enter image description here

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::

enter image description here

why Select(a => new) in first query show key column but select new does not show that?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Arian
  • 12,793
  • 66
  • 176
  • 300

1 Answers1

2

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() };
Hardrada
  • 728
  • 8
  • 19