2

从 SQL Server 选择数据时,READPAST什么方法可以让 NHibernate 使用提示?

4

1 回答 1

2

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

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

选项 #2 需要更多工作:

如果您没有使用 NHibernate.LockMode 之一,则可以将方言的 AppendLockHint() 覆盖为:

public override string AppendLockHint(LockMode lockMode, string tableName)
{
    if (lockMode == <lockModeYouWantToSacrificeForThis>)
    {
        return tableName + " with (readpast)";
    }
    return tableName;
}
于 2011-02-24T13:15:29.880 回答