简体   繁体   English

NHibernate DefaultUpdateEventListener和事件的问题

[英]Problems with NHibernate DefaultUpdateEventListener and events

I have a problem with the DefaultUpdateEventListener in NHibernate. 我在NHibernate中使用DefaultUpdateEventListener遇到问题。 I will update 2 objects and then i commit the session. 我将更新2个对象,然后提交会话。

The first object didn't come into the listener and the second object comes there. 第一个对象没有进入侦听器,第二个对象到达了侦听器。

So i checked with reflector to check what the problem is 所以我用反射器检查了一下是什么问题

First NHibernate will call the PerformSaveOrUpdate in the DefeultSaveOrUpdateEventListener there i see this 第一个NHibernate将在DefeultSaveOrUpdateEventListener中调用PerformSaveOrUpdate,我看到了

protected virtual object PerformSaveOrUpdate(SaveOrUpdateEvent @event)
{
    switch (this.GetEntityState(@event.Entity, @event.EntityName, @event.Entry, @event.Session))
    {
        case EntityState.Persistent:
            return this.EntityIsPersistent(@event);

        case EntityState.Detached:
            this.EntityIsDetached(@event);
            return null;
    }
    return this.EntityIsTransient(@event);
}

The differens of both object is the state The first object is detached and the second persistent 两个对象的区别在于状态:第一个对象是分离的,第二个对象是持久的

What makes a object persistent or detached in NHibernate ? 是什么使对象在NHibernate中持久存在或分离?

If i know what the difference is in this example i hope i can fix this in my code. 如果我知道此示例有什么不同,我希望可以在我的代码中解决此问题。

The load of both object are equal with session.Load 两个对象的负载与session.Load相等

I resolved the problem to implement the 我解决了实施问题
public override void OnSaveOrUpdate(SaveOrUpdateEvent @event) 公共重写void OnSaveOrUpdate(SaveOrUpdateEvent @event)

This event will be hit before the PerformSaveOrUpdate(SaveOrUpdateEvent @event) 将在PerformSaveOrUpdate(SaveOrUpdateEvent @event)之前命中此事件

On this time it doesn't matter if the object is persistent or detached 此时,对象是持久的还是分离的都没有关系

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM