Ritesh,
I don't think this has anything to do with nCommon - I think it's a
problem with nHibernate. But then again - I am not sure if there is
something else that I'm missing.
The very first transaction I do in an application (or sets of unit
tests) runs with 'read committed' isolation level no matter what is
specified as isolation level in nHibernate config or directly on the
transaction. Every subsequent transaction seems to be running with
isolation level set to whatever value I have.
So, pretty much I've got 2 sets of tests - one using nCommon, another
one using just ISession and ISession.BeginTransaction().
1. For nCommon usage there are 3 unit tests doing exactly the same:
using (UnitOfWorkScope scope = new UnitOfWorkScope
(IsolationLevel.ReadUncommitted))
{
NHRepository<Order> repository = new NHRepository<Order>();
IList<Order> orders = (from o in repository
where o.Id == 133268203
select o).ToList();
scope.Commit();
Assert.AreEqual(1, orders.Count);
}
2. For hNibernate there are couple of unit tests (almost the same,
just different variations of sessions and transactions), one of them
is as follows:
using (ISession session = Store.Local.Get<ISessionFactory>
("NHRepositoryTests.SessionFactory").OpenSession())
{
using (ITransaction transaction = session.BeginTransaction
(IsolationLevel.ReadUncommitted))
{
Order result = session.Get<Order>(133268223);
transaction.Commit();
Assert.IsNotNull(result);
}
using (ITransaction transaction = session.BeginTransaction
(IsolationLevel.ReadUncommitted))
{
Order result = session.Get<Order>(133268229);
transaction.Commit();
Assert.IsNotNull(result);
}
}
3. nHibernate config entry:
<property name="connection.isolation">ReadUncommitted</property>
For both of these cases i run SQL Profiler and look at AuditLogin
events which contain connection details. First connection ever will
run with 'set transaction isolation level read committed' while the
rest of them will run with "read uncommitted' set. I am also not 100%
sure as to how nHibernate manages the connections and whether I keep
getting the same connection over and over again, since the tests are
run sequentially, or whether nHibernate discards a connection and gets
a new one since I get a new ISession in different unit tests.
I haven't got to nHibernate latest source to build and confirm/deny
this behavior in the latest trunk version. Most likely this will have
to wait until I can find some time to dig into this further. But this
is where I ended up so far.
And if you want to replicate this behavior - just run any single test
with isolation level set to anything but ReadCommitted and trace in
SQL Profiler. You should see that your connection is set to a default
value of ReadCommitted. This is how I discovered it, because I have a
requirement to have all reads to be dirty.
Well, hope this helps.
Regards,
Alex
On Oct 20, 7:55 am, Ritesh Rao <
rao.rit...@gmail.com> wrote:
> Alex,
> Could you let me know how you are setting the isolation level on the parent
> unit of work scope? If you could give me a test case I can replicate I can
> take a look why the isolation level is not being set on the root.
>
> Thanks,
> Ritesh
>