How to set Nhibernate LINQ Command Timeout using Session.Query

半城伤御伤魂 提交于 2020-01-14 09:48:32

问题


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.

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.

Using Query returns an IQueryable<T>

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

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

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


回答1:


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


来源:https://stackoverflow.com/questions/20890395/how-to-set-nhibernate-linq-command-timeout-using-session-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!