7
votes

I would like to set the default transaction level to ReadCommitted in my Fluent NHibernate configuration. If I were using XML mapping files, I could add a key to my config file:

<add key="hibernate.connection.isolation" value="ReadCommitted" />

but I can't figure out how to accomplish this with Fluent configuration.

3

3 Answers

6
votes

Fluent NHibernate doesn't do anything with the transaction isolation, so the default will be whatever NHibernate defaults to. I don't know off the top of my head what that is.

We don't have an explicit method to set the isolation, but as it's just a configuration value you can use the Raw method to set the property.

MsSqlConfiguration.MsSql2008.Raw("connection.isolation", "isolation_level");

Source: https://web.archive.org/web/20100812054505/http://support.fluentnhibernate.org/discussions/help/45-default-isolation-level-for-transactions

5
votes

You should specify isolation level, when calling: BeginTransaction on your Session object.

...
ISession session = SessionFactory.OpenSession();
session.BeginTransaction(IsolationLevel.ReadCommitted);
...

Please refer to: NHibernate transactions for more details.

1
votes

With Fluent NHibernate v 2.x IsolationLevel() method can be used to globally set isolation level for transactions:

MsSqlConfiguration.MsSql2008
    .IsolationLevel(System.Data.IsolationLevel.ReadCommitted)