When running the following Linq query
ViewBag.AmountThisYear = db.Bookings
.Where(p => p.Id == id &&
p.StartDate.Year == DateTime.Now.Year)
.Sum(t => t.Price);
I get the following error when there are no results returned in the where clause
An attribute like "System.Decimal" is invalid because the materialized value is zero. Either the general parameter of the result type or the query should use a type with a null value.
How Sum Should Be Written To Deal With This Situation
source
share