使用EF更新行时的DateTime错误

时间:2012-08-23 16:37:58

标签: sql-server-2008 datetime entity-framework-4 datetime2

我有一个方法从数据库中的表中获取现有行并更新其中的一些值,然后保存这些更改。 quesiton中的表格包含以下列:

columns in table

进行更新的代码在这里:

        public void Update(Accommodation accommodation, string code, int supplierId)
        {
            var existingAccommodation = Get(a => a.Code == code && a.SupplierId == supplierId);

            DateTime now = DateTime.Now;

            existingAccommodation.ModifiedDate = now;
            existingAccommodation.Description = accommodation.Description;
            existingAccommodation.Introduction = accommodation.Introduction;
            existingAccommodation.Name = accommodation.Name;
            existingAccommodation.Strapline = accommodation.Strapline;
            existingAccommodation.Type = accommodation.Type;
            existingAccommodation.Processed = true;

            DataContext.SaveChanges();
        }

问题是,行DataContext.SaveChanges();会导致一个异常的异常:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

这是上面代码的名称

            Accommodation existingAccommodation = GetByCode(code, supplierId);
            if (existingAccommodation != null)
            {
                _accommodationRepository.Update(
                    accommodation, code, existingAccommodation.SupplierId);
            }

0 个答案:

没有答案