public override void Transact(Action <IRepository> work,
                                      IsolationLevel isolationLevel = ReadCommitted, RepositoryFlushMode flushMode = Commit)
        {
            // Restore the previous mode afterwards, just in case.
            FlushMode?previousMode = null;

            SessionAction(s =>
            {
                previousMode = s.FlushMode;
                s.FlushMode  = flushMode.ToFlushMode();

                // Arrange for a disposable transaction.
                using (var transaction = s.BeginTransaction(isolationLevel))
                {
                    // Handle the work within the transaction.
                    work(this);

                    // NHibernate's Transaction Dispose handles the Rollback.
                    transaction.Commit();
                }
            }, s =>
            {
                // Restore from the previous mode or current one if necessary.
                s.FlushMode = previousMode ?? s.FlushMode;
            });
        }
Example #2
0
 protected virtual void Transact(Action <IRepository> work
                                 , IsolationLevel isolationLevel = ReadCommitted
                                 , RepositoryFlushMode flushMode = Commit)
 {
     Repository.Transact(work, isolationLevel);
 }
 internal static FlushMode ToFlushMode(this RepositoryFlushMode mode)
 {
     return(LazyFlushModeMap.Value[mode]);
 }
 public abstract void Transact(Action <IRepository> work,
                               IsolationLevel isolationLevel = ReadCommitted, RepositoryFlushMode flushMode = Commit);