How can I use the READPAST hint in NHibernate?

蹲街弑〆低调 提交于 2019-12-24 03:16:31

问题


Is there any way I can get NHibernate to use the READPAST hint when selecting data from SQL Server?


回答1:


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


来源:https://stackoverflow.com/questions/5104695/how-can-i-use-the-readpast-hint-in-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!