Solved

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

Posted on 2013-06-13
2
602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

728 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