0
Hello I’m trying to make a chart in aspnetcore using EF, I have a table Events in it contains a FK Idarea that determines the area of the event I wanted to count how many events you have of each Idarea, for example how many events you have in the IT area, The graph itself is functional the problem is in the logic that I am not able to understand! Any help is welcome!
Follow the attempts ! OBS.: Total Event is are the tests I did the SUM works the graph but of course it adds up what has inside the field so it is not the case! No build error but no information appears on the chart
public IEnumerable<GraficoViewModel> ListaGrafico(int IdArea, int IdEvento)
{
var lista = _contexto.Evento.Include(a => a.Area)
.GroupBy(x => x.Id)
.Select(y => new GraficoViewModel
{
IdEvento = y.First().Id,
Descricao = y.First().Area.Descricao,
//TotalEvento = y.Sum(a =>a.IdArea)
//TotalEvento = y.Count(c =>c.IdArea == IdArea )
TotalEvento = y.Where(c =>c.IdArea == IdArea ).Count()
}).ToList();
}).ToList();
return lista;
}
Hello @Piscinão, don’t forget to accept the answer if it solves your problem. "Mark as useful" is optional and can be used by anyone.
– tvdias