viernes, 3 de mayo de 2013

Group By y Sum con linq

var ListaInfoLineasAgrupadas = (from l in _Factura.Lineas
                                                   group l by l.CuentaCosto into grupo
                                                   select new
                                                   {
                                                       CuentaCosto = grupo.First().CuentaCosto,
                                                       Proyecto = grupo.First().Proyecto,
                                                       ValorNeto = grupo.Sum(g => g.ValorNeto),
                                                       PesoLinea = 0
                                                    }
                                                   ).ToList();