views:

118

answers:

1

I have a Custom EventListener hooked into listen for SaveOrUpdates and now whenever I call Session.SaveOrUpdate on my object it inserts when it should update.

Here is my Event Listener:

public class CustomSaveEventListener : DefaultSaveEventListener
{

    protected override object PerformSaveOrUpdate(SaveOrUpdateEvent @event)
    {
        return base.PerformSaveOrUpdate(@event);
    }

}

Here is how it is configured (fluently):

 SessionFactory = Fluently.Configure()
              .Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.Is(connString)).ShowSql().DoNot.UseReflectionOptimizer)
              .Mappings(m => m.FluentMappings.AddFromAssemblyOf<INC_IncidentMap>())
              .ExposeConfiguration(c => c.EventListeners.SaveOrUpdateEventListeners = new ISaveOrUpdateEventListener[] { new CustomSaveEventListener() })
              .BuildConfiguration().BuildSessionFactory();

The reason I need the event listener is because I need to perform audit tracking on any/every entity persisted.

Has anyone ran into this issue? Any insight would be greatly appreciated.

A: 

Your problem is that you're replacing the DefaultSaveOrUpdateEventListener with one derived from DefaultSaveEventListener, thus treating every update as a save.

Derek Greer