During save I have an empty TextBox on my page because it is not required and the user decided not to fill it out.
From what I remember in VB.NET when I do the following it will save to the database as NULL, but in C# it seems to be saving as an empty string. I am using Entity Framework 6 DB First
myobject.Phone = PhoneTextBox.Text
Do I really have to do the following for every single non required textbox during save?
if (string.IsNullOrEmpty(txtPhone.Text))
{
myobject.Phone = null;
}
else
{
myobject.Phone = PhoneTextBox.Text;
}
if this is the case any suggestions on shortening the if statement or creating a function that takes care of it since it will always be the case when using textbox.