NHibernate - EventListener for SaveOrUpdateCopy

Posted by t-kehl on Stack Overflow See other posts from Stack Overflow or by t-kehl
Published on 2010-05-25T18:07:01Z Indexed on 2010/05/25 18:11 UTC
Read the original article Hit count: 293

Filed under:

Hi.

I do Update with SaveOrUpdateCopy(). Now, I have attached an event for this:

        this.EventListeners.SaveOrUpdateCopyEventListeners = new IMergeEventListener[] { new AuditableSaveOrUpdateCopyEventListener() };

In the AuditableSaveOrUpdateCopyEventListener, I have inherited from DefaultSaveOrUpdateCopyEventListener and overriden OnMerge():

public class AuditableSaveOrUpdateCopyEventListener : DefaultSaveOrUpdateCopyEventListener {
    public override void OnMerge(MergeEvent evt) {
        this.AddAuditableData(evt);
        base.OnMerge(evt);
    }

    public override void OnMerge(MergeEvent evt, System.Collections.IDictionary copyCache) {
        this.AddAuditableData(evt);
        base.OnMerge(evt, copyCache);
    }

    private void AddAuditableData(MergeEvent evt) {
        var entity = evt.Original as AuditableEntityBase;

        if (entity != null) {
            ...
        }            
    }
 }

But when I now change properties in entity, they will not be saved to the database.

Can someone give me a tip, how I can add my auditable-data for SaveOrUpdateCopy?

Thank you.

Best Regards, Thomas

© Stack Overflow or respective owner

Related posts about nhibernate