Getting this error:
System.Data.SqlClient.SqlException : The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range v
I had the same problem and solve it by put the [Column(TypeName = "datetime2")]
attribute to related properties, like below sample:
[Column(TypeName = "datetime2")]
public DateTime? PropertyName { get; set; }
Ensure that none of the not null fields in the DB(datetime) are left out while inserting/updating. I had the same error and on inserting values to those datetime fields the issue was solved.This occurs if the not null datetime fields are not assigned a proper value.
I had the same issue in my ASP.Net MVC application.
There were two model classes in my application that had DateTime properties.
upon investigating I noticed that the DateTime property of one model was nullable i.e. to make it date of Birth optional property
the other model had DateTime Property with Required data annotation (error occurs when saving this model)
my app is code first so I resolved the issue by setting datatype as DateTime2
[Column(TypeName="datetime2")]
then I ran the migration on package manager console.
Entity framework handles all the dates as a Datetime2, so, if your fields in the database are Datetime, this could be a problem. We had the same problem here, and from what we found, populating all the date fields and changing the datatype, are the most commom solutions