EntityValidationErrors inserting null datetime value

I’m trying to save a null value to a datetime column on a MS SQL database.
Whenever an exception is thrown and the dob property is set to null then db.savechanges throws the following error:

Validation failed for one or more entities. See
‘EntityValidationErrors’ property for more details.

It might seem redundant but would holterContents.dob = null as DateTime?; make a difference?

try
{
    holterContents.dob = new DateTime(Convert.ToInt32(infopatlines[38]), Convert.ToInt32(infopatlines[39]),
    Convert.ToInt32(infopatlines[40]));
}

catch (Exception a)
{
    holterContents.dob = null;
    Log.Error(a.Message);
}
db.C_HOLTERCONTENTS.Add(holterContents);
db.savechanges();


Source: .net

Leave a Reply