Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# - Lambda make Nullable<Int> = null if value is 0?

Posted on 2013-06-13
2
Medium Priority
?
642 Views
Last Modified: 2013-06-21
Hello all,

I have a property that I want to see if the value is 0 make it null.  How do I do that?  I have the one past making the value = 0 when null but then I need to revert back.

This is the first way making it 0:
 BusinessGroupID = entity.BusinessGroupID.GetValueOrDefault(0),

Need to go the other way now.
0
Comment
Question by:sbornstein2
2 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 620 total points
ID: 39244994
I think what you need is something like:

C#:
BusinessGroupID = entity.BusinessGroupID.GetValueOrDefault(0)==0?null:entity.BusinessGroupID

Open in new window


VB:
BusinessGroupID = If(entity.BusinessGroupID.GetValueOrDefault(0)=0,System.DBNull.Value,entity.BusinessGroupID)

Open in new window


Giannis
0
 

Author Closing Comment

by:sbornstein2
ID: 39266106
sorry for the delay this was perfect thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question