I am trying to figure out the best way to do what I thought would be easy. I have a database model called Line that represents a line in an invoice.
It looks roughly
Try something like this:
var invoices =
(from c in _repository.Customers
where c.Id == id
from i in c.Invoices
select new
{
Id = i.Id,
CustomerName = i.Customer.Name,
Attention = i.Attention,
Lines = i.Lines,
Posted = i.Created,
Salesman = i.Salesman.Name
})
.ToArray()
.Select (i => new InvoiceIndex
{
Id = i.Id,
CustomerName = i.CustomerName,
Attention = i.Attention,
Total = i.Lines.Sum(l => l.Total),
Posted = i.Posted,
Salesman = i.Salesman
});
Basically this queries the database for the records you need, brings them into memory and then does the summing once the data is there.