Solved

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

Posted on 2013-06-13
2
583 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 155 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

837 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