SqlDateTime overflow using NHibernate

◇◆丶佛笑我妖孽 提交于 2019-12-10 11:22:57

问题


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:


回答1:


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



来源:https://stackoverflow.com/questions/22272462/sqldatetime-overflow-using-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!