Try to do the GroupBy
and then a Select
to join its columns in a single if that is its 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; }
}
}
Post the final grid generation code... you want to do by c# or sql?
– Marllon Nasser
@Marllonnasser.. I want to do it in C# lambda. The final code is exactly the class I posted. But follow the code below: List<Reportavailable Reportaryavailableto(18,User logged in. Idusuario, User logged in.Cpf);
– Luciano Carlos
What you want together in the same columns are the fields
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; }
– Marco Souza
@Marconciliosouza actually I want to align the dates coming from the bank. Ie for each code, Subject, Description and shop I have 5 dates. And I want to put in a single line.
– Luciano Carlos