问题
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