How to set default transaction isolation level in Fluent NHibernate?

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

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

but I can’t figure out how to do this using the Free configuration.

+7
nhibernate fluent-nhibernate
source share
3 answers

Fluent NHibernate does nothing with transaction isolation, so NHibernate will be used by default. I do not know what it is.

We do not have an explicit method for setting isolation, but since this is 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

+6
source share

You must specify the isolation level when calling: BeginTransaction in the Session object.

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

See NHibernate Transactions for more details.

+5
source share

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

 MsSqlConfiguration.MsSql2008 .IsolationLevel(System.Data.IsolationLevel.ReadCommitted) 
+1
source share

All Articles