[Solved] Entity Framework Core Asp.Net Core 3.1 Error: SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated



Question: How do you resolve the error: SqlException: The conversion of a datetime2 data type to a DateTime data type resulted in an out-of-range value. The statement has been terminated

 

Answer: Take a look in your Database table, chances are that you have created a DateTime column in your Database table and made it nullable at the same time, you added a default-binding of getdate() to populate the column with default date.

However in your application code, you are not defining what that DateTime should be in the Database Table column, since you made the DateTime nullable in the database, it is expecting the DateTime to be populated by application code. You should explicitly pass in the DateTime in your data modal class or make the column field not nullable in your database table while you allow default-binding of getdate().

 

Call to Action: Sign up for a free account so to be notified when a new solution is found.