我尝试使用下一个代码设置IsolationLevel.ReadUncommitted
public class EntityRepository : RepositoryBase<Entity>, IEntityRepository
{
...
public void SomeFunction()
{
using (var transaction = Session.BeginTransaction(IsolationLevel.ReadUncommitted))
{
// Profiler log: set transaction isolation level read committed
try
{
Session.Query<Entity>().Count();
// Profiler log: select count(*) from dbo.Entity
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
}
...
}
但是我的Profiler说查询是在隔离级读取已提交的情况下执行的。
如果SomeFunction替换为
public void SomeFunction()
{
// 1. set isolation level uncommeted
using (var transaction = Session.BeginTransaction(IsolationLevel.ReadUncommitted))
{
// Profiler log: set transaction isolation level read committed
try
{
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
// 2. execute query
Session.Query<Entity>().Count();
// Profiler log: set transaction isolation level read uncommitted
// Profiler log: select count(*) from dbo.Entity
// 3. set isolation level committed
using (var transaction = Session.BeginTransaction(IsolationLevel.ReadCommitted))
{
// Profiler log: set transaction isolation level read uncommitted
try
{
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
}
查询与IsolationLevel.ReadUncommitted的调用。 步骤1.为会话设置readuncommitted隔离级别。 步骤2.调用我的查询,隔离级别readuncommitted。 步骤3.将会话隔离级别设置为readcommitted。
为什么会这样? 如何解决?
FluentNHibernate 1.3.0.733