我在数据库中使用 NHibernate 持久化我的对象
该App
对象定义了一个属性:
public virtual DateTime ReleaseDate { get; set; }
在映射类中:
Map(x => x.ReleaseDate).Not.Nullable();
在 sqlServer 2008 中,它的 dataType 是dateTime
且不可为空。
第一次它没有错误地保存到数据库。但是在更新应用信息后我遇到SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
但应用程序发布日期是有效的 dateTime :2/16/2014 2:21:58 AM
并且它不为空。
所以我很困惑为什么会引发这个异常?
ist<App> apps = session.QueryOver<Data.Model.App>()
.List()
.ToList();
.
.
.
.
for (int i = 0; i < apps.Count(); i++)
{
App appWithOldInfo = apps[i];
using (ITransaction transaction = session.BeginTransaction())
{
try
{
//updating app info
appWithOldInfo = UpdateAppInfo(appWithOldInfo, appWithNewInfo);
session.Update(appWithOldInfo);
transaction.Commit();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
看截图: