public static void Transaction(IsolationLevel level, Action transactional) { using (UnitOfWork.Start()) { // If we are already in a transaction, don't start a new one if (UnitOfWork.Current.IsInActiveTransaction) { transactional(); } else { IGenericTransaction tx = UnitOfWork.Current.BeginTransaction(level); try { transactional(); tx.Commit(); } catch { tx.Rollback(); throw; } finally { tx.Dispose(); } } } }
/// <summary> /// Flush the transaction by trying to commit and if nothing goes wrong then you're good. /// If commit goes wrong, the transaction will rollback the database /// </summary> /// <param name="isolationLevel">level of isolation for the transaction to flush</param> public void TransactionalFlush(IsolationLevel isolationLevel) { IGenericTransaction tx = BeginTransaction(isolationLevel); try { tx.Commit(); } catch { tx.Rollback(); throw; } finally { tx.Dispose(); } }
public void Commit(System.Data.IsolationLevel isolationLevel) { IGenericTransaction tx = BeginTransaction(isolationLevel); try { //forces a flush of the current unit of work tx.Commit(); } catch { tx.Rollback(); throw; } finally { tx.Dispose(); } }
public void TransactionalFlush(IsolationLevel isolationLevel) { IGenericTransaction tx = BeginTransaction(isolationLevel); try { //forces a flush of the current unit of work tx.Commit(); } catch (Exception ex) { tx.Rollback(); throw; } finally { tx.Dispose(); } }
public void TransactionalFlush(IsolationLevel isolationLevel) { // $$$$$$$$$$$$$$$$ gns: take this, when making thread safe! $$$$$$$$$$$$$$ //IUoWTransaction tx = UnitOfWork.Current.BeginTransaction(isolationLevel); IGenericTransaction tx = BeginTransaction(isolationLevel); try { //forces a flush of the current unit of work tx.Commit(); } catch { tx.Rollback(); throw; } finally { tx.Dispose(); } }
public void MultAdd(string beginDate, string endDate) { IGenericTransaction transaction = base.m_UnitOfWork.BeginTransaction(); try { for (int i = 0; DateTime.Parse(beginDate).AddDays((double)i) < DateTime.Parse(endDate); i++) { DateTime time = DateTime.Parse(beginDate).AddDays((double)i); DutyPlan entity = new DutyPlan { ID = time.ToString("yyyyMMdd") }; if (this.Get(entity.ID) == null) { entity.DutyDate = time; entity.MainDispatcher = null; entity.SecondDispatcher = null; base.Add(entity); } } transaction.Commit(); } catch (Exception exception) { transaction.Rollback(); base.logger.Debug(exception.Message); throw; } finally { if (transaction != null) { transaction.Dispose(); } } }