Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Nhibernate LINQ Command Timeout using Session.Query

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

like image 350
Kingpin2k Avatar asked Jan 02 '14 19:01

Kingpin2k


1 Answers

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);
like image 194
Kingpin2k Avatar answered Oct 23 '22 11:10

Kingpin2k