// Constructors public SqlUnitOfWorkScope(SqlTransactionScope transactionScope) { #region Contracts if (transactionScope == null) throw new ArgumentNullException(); #endregion // Arguments _transactionScope = transactionScope; }
// Methods public IUnitOfWorkScope Create() { // TransactionScope SqlTransactionScope transactionScope = new SqlTransactionScope(); // UnitOfWorkScope IUnitOfWorkScope unitOfWorkScope = new SqlUnitOfWorkScope(transactionScope); // Return return unitOfWorkScope; }
// Constructors public SqlCommandScope(string connectionString) { #region Contracts if (string.IsNullOrEmpty(connectionString) == true) { throw new ArgumentNullException(); } #endregion // Transaction Command SqlCommand command = SqlTransactionScope.Create(connectionString); if (command != null) { // Connection _connection = null; // Command _command = command; // Return return; } // Normal Command if (command == null) { // Connection _connection = new SqlConnection(connectionString); _connection.Open(); // Command _command = new SqlCommand(); _command.Connection = _connection; // Return return; } }
private void Insert_TransactionCommitButton_Click(object sender, EventArgs e) { // Transaction using (var transaction = new SqlTransactionScope()) { try { // Insert this.InsertData(); // Complete transaction.Complete(); } catch { // ...... } } // Refresh this.RefreshData(); }