Hi,
What is the best way to deal with null values in Linq.
I have this code which retrieves the customer contacts from the db but if the contact details don't exist it creates a new instance
void SetProperty(int _CustomerID)
{
Contacts_GetResult Contact;
if (Global.VariableStore._Contact == null)
{
Contact = Cd.Contacts_Get(_CustomerID).SingleOrDefault();
if (Contact == null)
Contact = new Contacts_GetResult();
Global.VariableStore._Contact = Contact;
}
else
{
Contact = Global.VariableStore._Contact;
}
if (Contact != null)
{
HomeNumber.Value = Contact.HomeNumber.ToString();
MobileNumber.Value = Contact.MobileNumber.ToString();
WorkNumber.Value = Contact.WorkNumber.ToString();
EmailAddress.Value = Contact.EmailAddress.ToString();
}
When it create the new contacts all the values are null which makes the below code fail as the value is null
HomeNumber.Value = Contact.HomeNumber.ToString();
I currently use:
if (Contact.HomeNumber != null)
HomeNumber.Value = Contact.HomeNumber.ToString();
Is there an easier way?
Thanks.