5

I'm trying to set IsolationLevel.ReadUncommitted using next code

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

But my Profiler says that query was executed with isolation level read committed.

If SomeFunction replace with

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

Query calls whith IsolationLevel.ReadUncommitted. Step 1. Set readuncommitted isolation level for session. Step 2. Call my query whith isolation level readuncommitted. Step 3. Set session isolation level readcommitted back.

Why is this happening? How to fix it?

FluentNHibernate 1.3.0.733

sadovnikav
  • 51
  • 2

0 Answers0