This is the query
I have highlighted in red where the object null reference error is.
How can i get round this
var invoices = from invoice in metaData.Invoice
join invoiceLine1 in invoiceLines on invoice.InvoiceId equals invoiceLine1.Invoice into il
from invoiceLine in il.DefaultIfEmpty()
join paymentInvoice1 in paymentInvoices on invoice.InvoiceId equals paymentInvoice1.Invoice into pi
from paymentInvoice in pi.DefaultIfEmpty()
join creditNote in metaData.CreditNote on invoice.InvoiceId equals creditNote.InvoiceId into cn
from cnCheck in cn.DefaultIfEmpty()
select new PaymentInvoiceClass
{
AccountId = invoice.AccountId,
Amt = invoiceLine.Amount,
CreditNoteId = cnCheck.CreditNoteId,
DateDue = invoice.DateDue,
InvoiceId = invoice.InvoiceId,
PaymentId = Guid.Empty,
Name = invoice.Reference,
PaidAmt = paymentInvoice != null ? paymentInvoice.Amount:0,
IsPosted = invoice.IsPosted,
IsRenewal = invoice.IsRenewal
};
var finalResult = invoices.Where(x => x.AccountId == AccountId);
finalResult = finalResult.Where(x => x.IsPosted.HasValue && !x.IsPosted.Value && x.Amt > x.PaidAmt);
return finalResult.ToArray();