How can I use the READPAST hint in NHibernate?

Is there a way to force NHibernate to use the READPAST hint when selecting data from SQL Server?

+2
source share
1 answer

Option # 1 Easy Way: SQL Query

 Session.CreateSQLQuery("select * from YourEntityTable with (readpast) where SomeColumn = :col") .AddEntity(typeof(YourEntity)) .SetString("col", value) .UniqueResult<YourEntity>(); 

Option number 2 Requires additional work:

If you are not using one of NHibernate.LockMode, you can override the dialect of AppendLockHint () like this:

 public override string AppendLockHint(LockMode lockMode, string tableName) { if (lockMode == <lockModeYouWantToSacrificeForThis>) { return tableName + " with (readpast)"; } return tableName; } 
+2
source

Source: https://habr.com/ru/post/1335113/


All Articles