문제

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: enter image description here enter image description here enter image description here

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top