I am trying to figure out the best way to handle this issue I have with ienumerable.sum null exception.
Basically I have a class that pulls the sum of its child objects as a return.
Something like this:
Part Class:
public ICollection<ContractLineItem> ContractLineItems { get; set; }
public float TotalReceiptSpendLong { get {
return ContractLineItems.Sum(s => s.TotalReceiptSpend);
} }
The contractlineitems class contains a ICollection to a receipts class which is totaled in the contractLineItems TotalReceiptSpend float. This works fine unless a contractlineitem has no receipts. It then throws a null exception. Is there a way to handle this best?