开发者

How can I use the READPAST hint in NHibernate?

开发者 https://www.devze.com 2023-02-13 17:26 出处:网络
Is there any way I can get NHibernate to use the READPAST h开发者_Python百科int when selecting data from SQL Server?Option #1 Easy way: SQL query

Is there any way I can get NHibernate to use the READPAST h开发者_Python百科int when selecting data from SQL Server?


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消