本文介绍了如何使用Session.Query设置Nhibernate LINQ命令超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道使用Session.Query时设置UnderlyingCriteria的方法吗?

Is anyone aware of a way to set the UnderlyingCriteria when using Session.Query?

我正在尝试为一个特定查询设置更具限制性的命令超时(或查询超时),并且试图避免在会话中的连接或其他查询上添加该约束.

I'm trying to set a more restrictive command timeout (or query timeout) for one specific query and I am trying to avoid adding that constraint on the connection or other querys in the session.

我发现在旧的QueryOver功能中,您可以使用类似的

I've found in the old QueryOver functionality you could use something like this

// QueryOver returns a IQueryOver<T,T> an nHibernate class
// with access to UnderlyingCriteria

var query = Session.QueryOver<Puppy>();
query.UnderlyingCriteria.SetTimeout(120);

问题在于它是旧的,有故障的,并且有很多功能上的问题.

The problem with that is it's old, buggy, and just has a slew of functional issues.

使用Query返回IQueryable<T>

 var query = (from c in Session.Query<Puppy>());

IQueryable是MS类,无法明显访问命令超时等.

IQueryable is a MS class with no apparent access to command timeouts etc.

另一种选择是在那一点上为所有命令设置会话命令超时,然后恢复为默认值,但是除了预先设置命令超时并离开之外,我没有看到任何公共机制可以这样做.这样,就像如何为NHibernate LINQ语句设置超时

Another option would be to somehow set the sessions command timeout for all commands, at that point, then revert to the default, but I'm not seeing any public mechanism for doing this, beside setting the command timeout up front and leaving it so, like How to set timeout for NHibernate LINQ statement

推荐答案

没关系,在Nhibernate的单元测试中找到了一个示例,他们为IQueryable添加了一些扩展方法.

Never mind, found an example in Nhibernate's unit tests, they've added some extension methods to IQueryable.

var query = (from c in Session.Query<Puppy>()).Timeout(12);

这篇关于如何使用Session.Query设置Nhibernate LINQ命令超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 00:05