Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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 …

730 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