Sunday, July 15, 2012 7:54 PM
There is one typical scenario: parent- child summary calculation.
There are usually existing two level summary calculation.
1 the sum between the different child columns.
result = this.fee1+ this.fee2;
2 the sum about the child rows.
result = this.OrderDetail.Sum(d => d.SubCost);
The fact is:
sum 2 runs like the SQL way, it omits all the null value, and give me the correct number.
sum 1 runs like the .net way , if there exist any null value, there are no result.
My question: Is there existing any elegant style to handling sum 1 calculation?
Perhaps, LS team could add one method like .SafeValue() , which can provide the same function like
- Edited by Bob Zhao Sunday, July 15, 2012 7:55 PM
Sunday, July 15, 2012 11:17 PMModerator
There is already something you can use for that. It's called GetValueOrDefault. It only applies to nullable properties.
It does exactly what you describe.
So your code would read:
result = this.fee1.GetValueOrDefault+ this.fee2.GetValueOrDefault;
Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer" By doing this you'll help people find answers faster.
Monday, July 16, 2012 8:15 PM
Wow, it works fine! Which this candy, it can save me a lot of time to struggle with the type safe issue and focus on the real calculation again!
Thanks a lot , Yann!