The conversion from the datetime2 data type to the datetime data type generates a value out of the range, datetime2datetime

Source: Internet
Author: User

The conversion from the datetime2 data type to the datetime data type generates a value out of the range, datetime2datetime

This error occurs when you use Entity Framework to operate databases.
This error is strange, in the garden saw a brother wrote that a big brother proposed the reason: http://www.cnblogs.com/plwang1990/articles/2025334.html
SqlServer2008 provides datetime2 data (more precise than datetime), while entity framework4 will default
The System. DateTime class is converted to the datetime2 type in sqlServer2008, and the attribute of the elements in your database is set to the datetime type,
If you convert datetime2 to datetime, the system will think that the data will be lost, so an error will be reported. (I think this TM is a design defect! Are you familiar with the default settings !)
After debugging, I found that this eldest brother was not totally correct. The valid range of datetime in SqlServer is January 1, January 1-9, 1753, December 31, 999. If the range is exceeded, EF converts datetime to datetime2, that is, the preceding error occurs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.