How could I select each group within an IGrouping with Dynamic Linq

49 Views Asked by At

I am trying to select from an IQueryable ome fields then from an IGrouping the amount on each of them. but apparently it doesn't seem to work the query looks like

var selectGrouping = 
"new (it.Key as Key 
, it.Select(it.CentroId).Distinct().Count() as CantidadCentros
, it.Select(it.OfertaFomativaId).Distinct().Count() as Acciones
, new (it.First().AccionFormativaId as AccionFormativaId
     , it.First().EstadoId as EstadoId
     , it.First().OfertaFormativaNombre as OfertaFormativaNombre
     , it.First().AmbitoNombre as AmbitoNombre
     , it.First().CantidadAcciones as CantidadAcciones
     , it.First().CentroId as CentroId) as Value)"

var select =
"new (AccionFormativaId
, EstadoId
, OfertaFormativa.Nombre as OfertaFormativaNombre
, Ambito.Nombre as AmbitoNombre
, OfertaFormativa.AccionFormativa.Count as CantidadAcciones
, CentroId)"

and the Linq query

var re = queryable
             .Select(select)
             .GroupBy(fields, "it")
             .Select(selecGrouping)
             .ToDynamicList();

this only returns the first of the items in the group but not each of them... how can I select of them in the IGrouping?

0

There are 0 best solutions below