简体   繁体   English

NHibernate拦截器->带参数的输出查询

[英]NHibernate Interceptor -> Output Query with Parameters

How do I implement an Interceptor that outputs the query WITH parameters? 如何实现输出带有WITH参数的查询的拦截器? I have searched the web and stackoverflow for a long time now and haven´t found an answer to my problem. 我已经搜索了很长时间的网络和stackoverflow,却没有找到解决我的问题的答案。 My Custom Interceptor-Class looks like this at the moment: 目前,我的自定义拦截器类如下所示:

public class SQLDebugOutput : EmptyInterceptor, IInterceptor {
        public override NHibernate.SqlCommand.SqlString OnPrepareStatement(NHibernate.SqlCommand.SqlString sql) {
            System.Diagnostics.Debug.WriteLine("NH: " + sql.ToString());
            return base.OnPrepareStatement(sql);
        }
}

The parameters in the query are displayed as questionmarks though and I need them for debugging purposes. 查询中的参数虽然显示为问号,但出于调试目的,我需要它们。 Also I´d prefer a solution not using the Log4Net Logger. 另外,我更喜欢不使用Log4Net Logger的解决方案。

So, is it possible at all to retrieve the parameter values of a query using an interceptor at all? 那么,是否根本有可能使用拦截器来检索查询的参数值? Maybe by overriding other methods of it? 也许通过覆盖其他方法呢?

The SqlString type that's supplied as a parameter to the OnPrepareStatement method has a GetParameters() method that returns a collection of Parameter objects. 作为参数提供给OnPrepareStatement方法的SqlString类型具有GetParameters()方法,该方法返回Parameter对象的集合。 Looking at the code suggests it should be possible to interrogate these objects and, hopefully, find what you're looking for. 查看代码表明应该可以查询这些对象,并希望找到所需的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM