Closed Atulin closed 3 years ago
maybe .Sum(c => (int?)c.WordCount)
?
It does appease the linter, yes, but it's still a workaround.
If I understand your problem, that's a correct workaround. .net's Enumerable.Sum
aggregate signature doesn't match same of sql COUNT
and return non-nullable type when aggregated over non-nullable sequence.
As designed.
In this scenario, if no chapters are published, the result will be
null
. It cannot be coalesced with??
sinceSum()
returns a non-nullable value, so there's no good way of giving this operation a default value of0
.The workaround is
but then the IDE complains that the left side of
??
will never be null.