This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hey All, Just wondering if I can do this in LINQ without without getting a InvalidOperationException UnitOfWork.Lines.Where(line=>line.AccountId = expectedAccountId&&line.Amount.HasValue).Average(line=>line.Amount) at the moment this throws an error if no lines match (ie it get's back a dbnull) Is there anyway I can tell it to do something a bit more elegant? |
|
|
There's nothing you can do to change this behaviour, but it will be fixed in the next nightly build (24 Sept): if you're returning into a nullable type and there are no results, aggregating operators like Average and Sum will now return null instead of throwing. |
|
|
thanks Ivan, awesome work. Now I can go back to my LINQ addiction.
Cheers Owen |
|