How to make a lambda pivot in a C #

3

I'm having a hard time making a pivot command on a list coming from the bank.

Abovetheselectthatiscomingwiththedata..ThedatefieldIwouldliketoplacethepivotcommand.

Followmyclass:

publicclassRelatorioPrincipalModel{publicstringCodRelatorio{get;set;}publicstringAssuntoRelatorio{get;set;}publicstringDescricaoRelatorio{get;set;}publicstringLojaRelatorio{get;set;}publicstringDataRelatorio01{get;set;}publicstringDataRelatorio02{get;set;}publicstringDataRelatorio03{get;set;}publicstringDataRelatorio04{get;set;}publicstringDataRelatorio05{get;set;}publicstringDataRelatorio06{get;set;}}

Andtheimageofwhatshouldappearonthepage:

I am bringing the information in a list identical to the first image and I will add the data in another list with the dates on the same line.

    
asked by anonymous 22.02.2016 / 21:42

1 answer

0

Try to make GroupBy and then a Select to join your columns into a single if that is your purpose. .

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;

namespace WebApplication1
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RelatorioPrincipalModel Disponivel = new RelatorioPrincipalModel()
            {
                CodRelatorio = "Teste",
                AssuntoRelatorio = "Teste",
                DescricaoRelatorio = "Teste",
                LojaRelatorio = "Teste",
                DataRelatorio01 = "DataRelatorio01",
                DataRelatorio02 = "DataRelatorio02",
                DataRelatorio03 = "DataRelatorio03",
                DataRelatorio04 = "DataRelatorio04",
                DataRelatorio05 = "DataRelatorio05",
                DataRelatorio06 = "DataRelatorio06",
            };

            List<RelatorioPrincipalModel> lstDisponivel = new List<RelatorioPrincipalModel>();
            lstDisponivel.Add(Disponivel);

            var lista = lstDisponivel
                .GroupBy(R => new { R.CodRelatorio, R.AssuntoRelatorio, R.DescricaoRelatorio, R.LojaRelatorio })
                .Select(R => new
                {
                    CodRelatorio = R.Key.CodRelatorio,
                    AssuntoRelatorio = R.Key.AssuntoRelatorio,
                    DescricaoRelatorio = R.Key.DescricaoRelatorio,
                    LojaRelatorio = R.Key.LojaRelatorio,
                    Data = R.Select(C => C.DataRelatorio01.ToString() + " "
                    + C.DataRelatorio02.ToString() + " " + C.DataRelatorio03.ToString() + " " + C.DataRelatorio04.ToString() +
                    " " + C.DataRelatorio05.ToString() + " " + C.DataRelatorio06.ToString()).FirstOrDefault(),

                }).ToList();

        }
    }

    public class RelatorioPrincipalModel
    {
        public string CodRelatorio { get; set; }
        public string AssuntoRelatorio { get; set; }
        public string DescricaoRelatorio { get; set; }
        public string LojaRelatorio { get; set; }
        public string DataRelatorio01 { get; set; }
        public string DataRelatorio02 { get; set; }
        public string DataRelatorio03 { get; set; }
        public string DataRelatorio04 { get; set; }
        public string DataRelatorio05 { get; set; }
        public string DataRelatorio06 { get; set; }
    }
}
    
23.02.2016 / 14:52