How do add NOLOCK with nHibernate?

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.

Leave a Comment