使用NHibernate的SqlDateTime溢出 [英] SqlDateTime overflow using NHibernate
问题描述
$ b
App
对象有一个定义的属性:
public virtual DateTime ReleaseDate {get;组; }
在mappingClass中:
Map(x => x.ReleaseDate).Not.Nullable();
在sqlServer 2008中它的dataType是 dateTime
并且不能为空。
第一次将它保存到数据库中,没有错误。但更新应用程序信息后,我遇到 SqlDateTime溢出。必须介于1/1/1753 12:00:00 AM和12/31/9999 11:59:59 PM之间。
但是应用程序发布日期是一个有效的日期时间: 2/16/2014 2:21:58上午
它不是空的。
ist< App> apps = session.QueryOver< Data.Model.App>()
具有
.List()
.ToList();
。
。
。
。
for(int i = 0; i< apps.Count(); i ++)
{
App appWithOldInfo = apps [i];
使用(ITransaction transaction = session.BeginTransaction())
{
try
{
//更新应用程序信息
appWithOldInfo = UpdateAppInfo (appWithOldInfo,appWithNewInfo);
session.Update(appWithOldInfo);
transaction.Commit();
catch(Exception ex)
{
Debug.WriteLine(ex.Message);
查看截图:
解决方案感谢您的有用评论。
code> deviceLastActivityDate 的数据库对象
列表与LT;装置>设备= session.QueryOver< Data.Model.Device>().List()。ToList();
在将一些设备对象添加到数据库之后进行建模。
这个属性是null,但是我没有定义LastActivityDate作为一个可以为null的属性。所以这个对象是在app对象的同一个session中的。当我刷新会话,因为LastActivityDate
为空,SqlDateTime异常上升!
这很简单。但我花了几个小时找到它!
I persist my objects using NHibernate in the database
the
App
object have a property defined:public virtual DateTime ReleaseDate { get; set; }
in the mappingClass:
Map(x => x.ReleaseDate).Not.Nullable();
which in the sqlServer 2008 its dataType is
dateTime
and is not nullable.for the first Time it saves to database with no error. but after updating app info I encounter
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
but the app release date is a valid dateTime :
2/16/2014 2:21:58 AM
and it's not null.so Im confused why this exception raise?
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); } }
see the screenshots:
解决方案thanks guys for your helpful comments.
The problem wast That I was fetching
device
object from DB which has a propertyLastActivityDate
List<Device> devices = session.QueryOver<Data.Model.Device>().List().ToList();
I had added this property to model after addding a device object with some info to the DB. this property was null, but I haden't defined LastActivityDate as a nullable property.
so this object was in the same session of app object. when I flushed the session, because
LastActivityDate
was null, SqlDateTime exception rised!it's simple. but I spend hours to find it!!
这篇关于使用NHibernate的SqlDateTime溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!