I have a query in LINQ
where I use SumAsync
, however when my entity is empty I have the exception:
The cast to value type 'System.Decimal' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.
The query I'm trying to do is as follows
var valor = await db.Exemplos.SumAsync(a => a.Valor);
How can I work around this and make SumAsync
return 0 if my entity does not have data yet?