Solved

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

Posted on 2013-06-13
2
544 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
Comment Utility
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
Comment Utility
sorry for the delay this was perfect thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now