I am creating a method that collects accumulated totals throughout the month. The problem is that there may not be charges for some of the items in a given month so no rows would be returned.
I can see how this would error with no data:
double fuelCost = (double)(from a in db.EquipmentFuelLogs
where a.wdEquipmentMainGeneralOID == vehicleKey &&
(monthBeginDate < a.Date1 && a.Date1 < monthEndDate)
select a.TotalCost).Sum();
What is the best approach to detect no fuel transactions for that month and set the fuel cost to 0? Just do a try catch? This article spoke of the problem but no solution.