Datetime2 Data Type

Source: Internet
Author: User

The. NET Entity Framework builds the website data layer and assigns values to the datetime type attribute of an object.
An exception that does not match the type is as follows:

System. Data. sqlclient. sqlexception: the conversion from datetime2 data type to datetime data type generates a value out of the range.

Solution:

Set the automatically generated code in the *. Designer. CS File

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]        [DataMemberAttribute()]        public global::System.DateTime addtime        {            get            {                return _addtime;            }            set            {                OnaddtimeChanging(value);                ReportPropertyChanging("addtime");                _addtime = StructuralObject.SetValidValue(value);                ReportPropertyChanged("addtime");                OnaddtimeChanged();            }        }        private global::System.DateTime _addtime;        partial void OnaddtimeChanging(global::System.DateTime value);        partial void OnaddtimeChanged();

 

Change

 

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]        [DataMemberAttribute()]        public Nullable<global::System.DateTime> addtime        {            get            {                return _addtime;            }            set            {                OnaddtimeChanging(value);                ReportPropertyChanging("addtime");                _addtime = StructuralObject.SetValidValue(value);                ReportPropertyChanged("addtime");                OnaddtimeChanged();            }        }        private Nullable<global::System.DateTime> _addtime;        partial void OnaddtimeChanging(Nullable<global::System.DateTime> value);        partial void OnaddtimeChanged();

 

 

 

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.