如何通过功能NHibernate添加事件监听器? [英] how to add event listener via fluent nhibernate?

查看:232
本文介绍了如何通过功能NHibernate添加事件监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个事件侦听器(I preUpdateEventListener)加NH,但我似乎无法找到使用流利的配置时的一个例子。

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.

我希望能够添加监听器,当我创建的会话工厂,例如:当以下code是执行。

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.FluentMappings.AddFromAssemblyOf())                   .BuildSessionFactory();

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

任何人都知道如何做到这一点?

Anyone know how to do this?

推荐答案

晚答案,发现你的问题,当我试图做同样的。发现应该是一个解决方案:

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()});

这篇关于如何通过功能NHibernate添加事件监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆