如何在NHibernate中使用READPAST提示?

时间:2011-02-24 12:31:55

标签: sql-server nhibernate query-hints

从SQL Server中选择数据时,有没有办法让NHibernate使用the READPAST hint

1 个答案:

答案 0 :(得分:2)

选项#1简单方法:SQL查询

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

选项#2需要更多工作:

如果你没有使用NHibernate.LockMode,你可以将dialect的AppendLockHint()覆盖为:

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