Print Page | Close Window

question regarding to the anonymous type

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1498
Printed Date: 27-Apr-2025 at 4:59pm


Topic: question regarding to the anonymous type
Posted By: monkeyking
Subject: question regarding to the anonymous type
Date Posted: 27-Sep-2009 at 9:49pm
the red squared section can crash the program when it's a null, what i want to do is converting the value (of debtorSales, cashSales or grossTotal) into 0 when it's a null, but in anonymous type, I don't think i can put any logic statment inside, such as if statement. so is there any way to resolve it?

Regards,
John





Replies:
Posted By: kimj
Date Posted: 28-Sep-2009 at 3:16pm
You can check for nulls when summing -
 
...   .Sum(o => o.SALES_PRICE == null ? 0 : o.SALES_PRICE)
 
 


Posted By: monkeyking
Date Posted: 28-Sep-2009 at 5:56pm
Thanks, I think your way should work logically, but unfortunately the same error occurs.

all other properties doesn't have any problems, the problem only occur on 'cashSales' (even not in debtorSales), i'm sure for that.





Posted By: kimj
Date Posted: 29-Sep-2009 at 7:51pm
Oh sorry.  This has already been fixed in current bits (for a separate problem) and that's what I tested against when answering previously.  So that's the good news - it will be fixed in the mid-October release.  The bad news, I don't have a workaround for you to use right now.



Print Page | Close Window