I already know that workaround before I created this post.
I mean why this is treat as "by design" behavior and not plan to fix it.
That's why I posted it here instead of the nhusers groupd.

On Monday, March 31, 2014 4:14:16 AM UTC+8, Ricardo Peres wrote:
>
> 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