score:2

I think your Linq query is almost perfect you just need to select new ViewModels:

from c in Invoices
join i in InvoiceItems on c.InvoiceId equals i.InvoiceId
join pi in PaymentInvoices on c.InvoiceId equals pi.InvoiceId
select new InvoiceViewModel {
    InvoiceId = c.InvoiceId,
    CustomerName = c.CustomerName,
    TotalofInvoice = c.InvoiceItems.Sum(invoiceitem => invoiceitem.Total(),
    AmountAllocated = ...
    Outstanding = ...
};

Related Articles