How can i made a pivot for this

后端 未结 1 922
伪装坚强ぢ
伪装坚强ぢ 2021-01-15 16:35

I have linq that return my data in this format

Servicio2 | Indicador  | Accion1
Servicio2 | Indicador  | Accion2
Servicio1 | Indicador1 | Accion1
Servicio1 |         


        
相关标签:
1条回答
  • 2021-01-15 17:11

    First portion uses your linq-entities provider, but after AsEnumerable it uses Linq to objects in order to return a comma seperated list

    I changed the last property to give it an alias

    AggregateProperty = xx.Acciones.Aggregate((current, next) => current + ", " + next)

     (from A in db.IndicadorServicioAccion
                                .Include("Accion")
                                .Include("IndicadorServicio")
                                .Include(i => i.IndicadorServicio.Indicador)
                        where
                            A.Usuario.IDUsuario == id
                            && A.Permiso == true
                    group A by new { A.IndicadorServicio.Indicador.nombreIndicador, A.IndicadorServicio.Servicio.Descripcion } into ag
                    select new
                         {
                            ag.Key.nombreIndicador,
                            ag.Key.Descripcion,
                            Acciones = ag.Select(x => x.Accion.Descripcion) 
                         }).AsEnumerable().Select(xx => new
                         {
                           xx.Descripcion,
                           xx.nombreIndicador,
                           AggregateProperty = xx.Acciones.Aggregate((current, next) => current + ", " + next)
                         });
    
    0 讨论(0)
提交回复
热议问题