void CargarFacturas() { List <dynamic> facturasConDetalle = new List <dynamic>(); List <Invoice> facturas = new List <Invoice>(); List <InvoiceDetail> detalleFacturas = new List <InvoiceDetail>(); facturasConDetalle = repository.GetAllInvoicesAndDetails(); facturas = repository.GetAllInvoices().Select(x => new Invoice { id = x.id, nroinvoice = x.nroinvoice, company = x.company, customer = x.customer, datecreate = x.datecreate, }).ToList(); detalleFacturas = repository.GetAllInvoicesDetails().Select(x => new InvoiceDetail { id = x.id, idInvoice = x.idInvoice, productname = x.productname, quantity = x.quantity, unitprice = x.unitprice, subtotal = x.subtotal }).ToList(); //Agregamos detalle a la Lista foreach (var factura in facturas) { factura.InvoiceDetails.AddRange(detalleFacturas.Where(x => x.idInvoice == factura.id).ToList()); factura.ammount = factura.InvoiceDetails.Select(x => x.subtotal).Sum(); factura.nroproducts = factura.InvoiceDetails.Select(x => x.quantity).Sum(); } gvFacturas.DataSource = facturas; gvFacturas.DataBind(); gvDetalle.DataSource = null; gvDetalle.DataBind(); }