I am trying to translate the following query:
SELECT STATE, COUNT(*) FROM MYTABLE GROUP BY STATE;
Into a lambda expression. I am using C# a
This one is good
public IEnumerable PorcentajeState(Guid id) { return _context.Sates.Where(a => a.Id == id) .GroupBy(a => a.StateId) .Select(g => new { g.Key, Count = g.Count() }); }
But try this.
public IEnumerable PorcentajeState(Guid id) { return _context.Sates.Where(a => a.Id == id) .GroupBy(a => a.StateId) .Select(g => new { g.Key.StateId, Count = g.Count() }); }