Problems with NHibernate DefaultUpdateEventListener and events
I have a problem with the DefaultUpdateEventListener in NHibernate. I will update 2 objects and then i commit the session.
The first object didn't come into the listener and the second object comes there.
So i checked with reflector to chec开发者_开发技巧k what the problem is
First NHibernate will call the PerformSaveOrUpdate in the DefeultSaveOrUpdateEventListener there i see this
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 ?
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
I resolved the problem to implement the
public override void OnSaveOrUpdate(SaveOrUpdateEvent @event)
This event will be hit before the PerformSaveOrUpdate(SaveOrUpdateEvent @event)
On this time it doesn't matter if the object is persistent or detached
精彩评论