views:

538

answers:

2

I want to add an event listener (IPreUpdateEventListener) to add NH but I can't seem to find an example when using a fluent configuration.

I want to be able to add the listener when I create the session factory, e.g. when the following code is execute.

_sessionFactory = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString).ShowSql()) .Mappings(m => m.FluentMappings.AddFromAssemblyOf()) .BuildSessionFactory();

Anyone know how to do this?

+6  A: 

Late answer, found your question when I was trying to do the same. Found a solution that should work:

_sessionFactory = Fluently.Configure()
   .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString).ShowSql())
   .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Entity>())
   .ExposeConfiguration(c => c.EventListeners.PreUpdateEventListeners = new IPreUpdateEventListener[] {new AuditEventListener()});
BengtBe
+1  A: 

I totally need to check StackOverflow before I post... http://ferventcoder.com/archive/2009/11/18/nhibernate-event-listener-registration-with-fluent-nhibernate.aspx

ferventcoder