Question

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

Pas de solution correcte

Autres conseils

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);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top