使用NHibernate的SqlDateTime溢出 [英] SqlDateTime overflow using NHibernate

查看:172
本文介绍了使用NHibernate的SqlDateTime溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

App 对象有一个定义的属性:

p>

  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> device
具有 LastActivityDate 的数据库对象

列表与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 property LastActivityDate

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆