How do add NOLOCK with nHibernate?

mrblah picture mrblah · Aug 19, 2009 · Viewed 27.6k times · Source

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

Answer

AntonioR picture AntonioR · Nov 18, 2010

SetLockMode(LockMode.None) or connection.isolation ReadUncomitted does NOT append a NOLOCK to your queries.

Ayende goes into the correct answer on his blog:

If you're using <sql-query> you can do the following:

<sql-query name="PeopleByName">
    <return alias="person"
                    class="Person"/>
    SELECT {person.*}
    FROM People {person} WITH(nolock)
    WHERE {person}.Name LIKE :name
</sql-query>

Note the WTIH(nolock) appended to the FROM clause.