title: C# Shared Transactions and NHibernate using IRepository
body: <p>I'm looking into implementing the IRepository pattern using NHibernate and I have question that I've not been able to answer searching the net.</p>
  
  <p>Assume I have 3 Repositories, PersonRepository, PersonAddressRepository and PersonAccountRepository. Now assume that business logic dictates that there be an "Deactivate Person" process that calls PersonRepository.Deactivate(), PersonAddressRepository.Deactivate() and PersonAccountRepository.Deactivate().</p>
  
  <p>I want to be able to do something along the lines of..</p>
  
  <pre><code>using (ITransaction transaction = session.BeginTransaction()) { 
      session.Update(Person);
      session.Update(PersonAddress);
      session.Update(PersonAccount);
  }
  </code></pre>
  
  <p>So that if any of those updates fail that the entire process rolls back within the database. Now at the moment my understanding of NHibernate is you can only create a Session per object so..</p>
  
  <pre><code>var cfg = new Configuration();
  cfg.Configure();
  cfg.AddAssembly(typeof(Person).Assembly);
  ISessionFactory sessionFactory = cfg.BuildSessionFactory();
  using (ISession session = sessionFactory.OpenSession()) {
      using (ITransaction transaction = session.BeginTransaction()) {
      session.Save(Person);
  }
  </code></pre>
  
  <p>Is this correct or am I mistaken? What are the best practices for Transactions regarding multi table updates and Transactions with regards to NHibernate.</p>
  
  <p>Thanks in advance.</p>