我有一种方法可以从数据库中的表中获取现有行并更新其中的一些值,然后保存这些更改。question 中的表有以下几列:
进行更新的代码在这里:
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);
}