var total = query.Sum(x => (double?) x.Income);

Replace double for single, int, long, etc.

By the way, the proper place to ask questions is the nhusers mailing list, 
not this one.

RP

On Sunday, March 30, 2014 4:42:24 PM UTC+1, Mouhong Lin wrote:
>
> Hi guys,
>
> I get an exception saying "Value cannot be null" when i execute this query 
> (NH 3.3.3):
>
> var total = query.Sum(x => x.Income);
>
> The exception happens when the query returns no result.
> I found there's already a Jira issue about this: 
> https://nhibernate.jira.com/browse/NH-3113 
>
> But why won't fix? It's really not usable if this query throws exception. 
> In every application that need to do reporting will encounter this.
> And this violate the semantic of the sum and linq to objects, right? 
> If this should throw exception, why query.Count() don't throws? 
> (I understand the technical reason of this, just saying why the semantic 
> of these are not consistent)
>
> If L2S or EF behaves the same, I think it's their bug. Not because it's a 
> good thing.
> Workaounds like this "var sum = myQuery.Sum(x => (int?)x.Prop) ?? 0" make 
> my code really ugly. 
>
> Ideas? 
>
>
>
> ------------------------------
> Mouhong
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to