Linq - Uso do CASE para agrupamento por mês


var dataContext = new Entities();

            var mes = from enc in dataContext.Tabela
                              select new
                              {
                                  conta = enc.CONTA,
                                  Janeiro = (enc.DATA.Value.Month == 1 ? enc.VALOR.Value : 0),
                                  Fevereiro = (enc.DATA.Value.Month == 2 ? enc.VALOR.Value : 0),
                                  Março = (enc.DATA.Value.Month == 3 ? enc.VALOR.Value : 0),
                                  Abril = (enc.DATA.Value.Month == 4 ? enc.VALOR.Value : 0),
                                  Maio = (enc.DATA.Value.Month == 5 ? enc.VALOR.Value : 0),
                                  Junho = (enc.DATA.Value.Month == 6 ? enc.VALOR.Value : 0),
                                  Julho = (enc.DATA.Value.Month == 7 ? enc.VALOR.Value : 0),
                                  Agosto = (enc.DATA.Value.Month == 8 ? enc.VALOR.Value : 0),
                                  Setembro = (enc.DATA.Value.Month == 9 ? enc.VALOR.Value : 0),
                                  Outubro = (enc.DATA.Value.Month == 10 ? enc.VALOR.Value : 0),
                                  Novembro = (enc.DATA.Value.Month == 11 ? enc.VALOR.Value : 0),
                                  Dezembro = (enc.DATA.Value.Month == 12 ? enc.VALOR.Value : 0)
                              };
                           
         
            dataGridView1.DataSource = mes;

Comentários

Postagens mais visitadas deste blog

Delphi - ReportBuilder – Conhecendo os Recursos deste Gerador de Relatórios

Delphi - Stringgrid com Alinhamento à Direita, à Esquerda e Centralizado

Delphi - Instalando a versão Trial do Delphi 2007 for Win 32