views:

993

answers:

2

Hi,

How do you add NOLOCK when using nhibernate? (criteria query)

+5  A: 

For NHibernate 2.1, use the SetLockMode method off of CreateCriteria.

session.CreateCriteria(...).SetLockMode(LockMode.None).List();
jasonlaflair
Can this be done using NHibernate.Linq somehow?
mxmissile
Note that, according to my experiments, this has *nothing* to do with the SQL hint NOLOCK, it is entirely related to how NHibernate locks objects internally in sessions
mbp
+1  A: 

If you are going to use it in a lot of your queries, you can set it as default via the configuration property connection.isolation.

<property name="connection.isolation">ReadUncommitted</property>

Check out the documentation on this property.

Rohit Agarwal