Is there any way I can get NHibernate to use the READPAST
hint when selecting data from SQL Server?
Asked
Active
Viewed 876 times
2
1 Answers
3
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 #2 Requires more work:
If you're not using one of NHibernate.LockMode you can override dialect's AppendLockHint() to something like:
public override string AppendLockHint(LockMode lockMode, string tableName)
{
if (lockMode == <lockModeYouWantToSacrificeForThis>)
{
return tableName + " with (readpast)";
}
return tableName;
}

Community
- 1
- 1

Filip Zawada
- 824
- 1
- 7
- 17
-
1Or perhaps you could define your own LockMode enum with the same values as NHibernate's and add one with an explicit value, then check that in your custom dialect (cast the NH LockMode to yours). This takes advantage of the fact that C# enums can be any value, not just the ones defined. – Raif Atef May 04 '11 at 12:31