bilal-fazlani/tracker-enabled-dbcontext

Datetime2 conversion error when saving

walmanarias opened this issue · 1 comments

The conversion of a datetime2 data type to a datetime when trying to save the entitities

This is a common error people face with Entity Framework. This occurs when the entity associated with the table being saved has a mandatory datetime field and you do not set it with some value.

The default datetime field is created with a value of 01/01/0001 and will be used in place of null. This will be sent to the datetime column which can hold date values from 01/01/1753 00:00:00 and onwards, but not before, leading to the out-of-range exception.

This can be resolved by either modifying the database field to accept null or by initializing the field with a value.