Inline if in linq

Posts   
 
    
Jed123
User
Posts: 4
Joined: 28-Oct-2010
# Posted on: 28-Oct-2010 16:10:11   

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();
MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
Jed123
User
Posts: 4
Joined: 28-Oct-2010
# Posted on: 29-Oct-2010 09:38:49   

I cant use that but this seems to of working not sure how

paymentInvoice.Amount != null ? paymentInvoice.Amount:0

Thanks for the help