When I execute a program written in EF 6.0, the error is as follows: Conversions from the datetime2 data type to the datetime data type produce an out-of-range value.
Development environment:
Visual Studio 2013
. NET Framework 4.5
Entity Framework 6.0
After online collection, white pillow in his blog to write the detailed reasons:
SQLSERVER2008 provides datetime2 types of data (more accurate than datetime), and entity framework4 defaults to C # The System.DateTime class in the sqlServer2008 is converted to the DateTime2 type in the system, and the attributes of the elements in your database are set to the DateTime type, and converting datetime2 to a DateTime will be considered as losing data, so it will be an error.
There are two types of solutions available on-line: 1, explicit assignment, 2. Change database field to datetime2 type. Just think that these two solutions have relatively large limitations, so did some attempts to find some ways to use, specifically as follows:
1. If your datetime Type field is not assigned a value when added, set the "nullable" property of the field to true in the Model browser;
2. If you have a DateTime type field and you need to assign a value, set the value explicitly instead of having the database script set the default value;
3, update the same as the new treatment can be;
Conversions from the DATETIME2 data type to the datetime data type produce an out-of-range value