The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value
Assign datetime value in code in silve开发者_Python百科rlight and save it to db by domainservice and EF: DateCreated = DateTime.Now
in database, the mapped column datetype is datetime, not datetime2.
then got following error: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
How to fix it?
In your model put a questionmark behind the datatype.
public DateTime? myDate {get; set;}
This will allow NULL to be written in the database.
精彩评论