Basically when I do the following query, if no leads were matched the following query throws an exception. In that case I\'d prefer to have the sum equalize 0 rather than an
Try:
double earnings = db.Leads.Where(l => l.ShouldBeIncluded).Sum(l => (double?) l.Amount) ?? 0;
The query "SELECT SUM([Amount])" will return NULL for empty list. But if you use LINQ it expects that the "Sum(l => l.Amount)" returns double and it doesn't allow you to use "??" operator to set 0 for empty collection.
In order to avoid this situation you need to make LINQ expect "double?". You can do it by casting "(double?)l.Amount".
It doesn't affect the query to SQL but it makes LINQ working for empty collections.