Here is a question of interest
return _projectDetail.ExpenditureDetails
.Where(detail => detail.ProgramFund == _programFund
&& detail.Expenditure.User == _creditCardHolder)
.Sum(detail => detail.ExpenditureAmounts.FirstOrDefault(
amount => amount.isCurrent && !amount.requiresAudit)
.CommittedMonthlyRecord.ProjectedEac);
ProjectDetails table structure (1 to many) ExpanditureDetails
CostsDetails (1 to many)
ExpanditureAmounts consumables (1 to 1) CommittedMonthlyRecords
ProjectedEac is the decimal field in CommittedMonthlyRecords.
The problem I discovered in Unit test (albeit an unlikely event) is that the following line may be null:
detail.ExpenditureAmounts.FirstOrDefault(
amount => amount.isCurrent && !amount.requiresAudit)
My initial request was a nested loop in which I would make several trips to the database, which I do not want to repeat. I looked at what looks like some similar questions, but the solution does not seem to fit .
Any ideas?