private void Insert_TransactionRollbackButton_Click(object sender, EventArgs e) { // Transaction using (var transaction = new SqlTransactionScope()) { try { // Insert this.InsertData(); // Throw throw new Exception(); // Complete transaction.Complete(); } catch { // ...... } } // Refresh this.RefreshData(); }
// Methods public TransactionScopeProvider Create() { // TransactionScope var transactionScope = new SqlTransactionScope(); // TransactionScopeProvider var transactionScopeProvider = new SqlTransactionScopeProvider(transactionScope); // Return return(transactionScopeProvider); }
// Methods public IUnitOfWorkScope Create() { // TransactionScope SqlTransactionScope transactionScope = new SqlTransactionScope(); // UnitOfWorkScope IUnitOfWorkScope unitOfWorkScope = new SqlUnitOfWorkScope(transactionScope); // Return return(unitOfWorkScope); }
// Constructors public SqlUnitOfWorkScope(SqlTransactionScope transactionScope) { #region Contracts if (transactionScope == null) { throw new ArgumentNullException(); } #endregion // Arguments _transactionScope = transactionScope; }
// Constructors public SqlTransactionScopeProvider(SqlTransactionScope transactionScope) { #region Contracts if (transactionScope == null) { throw new ArgumentNullException(); } #endregion // Default _transactionScope = transactionScope; }