问题描述
我正在处理一些为NHibernate生成ICriteria查询的代码.它们使用ActiveRecord和ActiveRecordMediator.FindAll()
I'm working with some code that generates ICriteria queries for NHibernate. They get executed using ActiveRecord and ActiveRecordMediator.FindAll()
对于某些查询,我需要通过在SELECT语句末尾添加OPTION (HASH JOIN)
提示来优化它们.有什么快速的方法可以做到这一点吗?
For certain queries, I need to optimise them by adding on an OPTION (HASH JOIN)
hint at the end of the SELECT statement. Is there a quick way I can do this?
我不想使用纯SQL重写查询.好吧,我很乐意,但是它们太复杂了.但是,举例来说,如果有一种简单的方法可以在将SQL注入SQL Server之前对其进行陷阱和修改,那我会很高兴的.
I don't want to rewrite the queries using plain SQL. Well, I'd love to, but they're too complicated. But if, for example, there's an easy way I can trap and modify the SQL before it's pumped off to SQL Server, I'd be happy.
推荐答案
实现IInterceptor并在OnPrepareStatement()中进行修改.然后将您的拦截器传递给ISessionFactory.OpenSession().
Implement an IInterceptor and do your modifications in OnPrepareStatement(). Then pass your interceptor to ISessionFactory.OpenSession().
或者您可以尝试在方言中注册自定义功能. (示例)
Or you could try registering a custom function in your dialect. (example)
这篇关于向NHibernate查询添加SQL查询选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!