如何在NHibernate中的所有查询中添加一些SQL [英] How can i add some sql to all querys in NHibernate
本文介绍了如何在NHibernate中的所有查询中添加一些SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个版本控制系统,因此所有查询都必须添加一个sql
I want a version control system and therefore all querys must add a piece of sql
当前记录显示的位置.
但是在什么地方,我可以在所有查询中添加那条sql? 还是我可以通过事件来完成?
But what place, can i add that piece of sql to all querys ? or could i do it with events?
推荐答案
制作一个实现IInterceptor的类
Make a class that implements IInterceptor
然后将该类作为会话的参数,例如
then give that class as param to the session like
SessionManager.SessionFactory.OpenSession(new newClass()));
您需要在课程中提供实现
in the class you need to give your implementation to
public NHibernate.SqlCommand.SqlString OnPrepareStatement(NHibernate.SqlCommand.SqlString sql)
{
}
将在此会话上运行的每个查询都将在此处被拦截,您可以在其中添加一些SQL
each query that will run on this session will be intercept here and there you can add some sql
这篇关于如何在NHibernate中的所有查询中添加一些SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文