/// <summary> /// Performs multiple updates in a single transaction, with disparate (but presumably related) data. /// </summary> /// <param name="dataSet1">first data set</param> /// <param name="dataSet2">second data set</param> public void UpdateMultipleDetails(CustomDataSet dataSet1, SpecialDataSet dataSet2) { // Prepare the connection IDbConnection connection = new System.Data.SqlClient.SqlConnection( /* Connection string goes here*/ ); Library.TransactionWrapper transactionWrapper = new Library.TransactionWrapper(connection); // Hook data for first operation CustomDataUpdate customDataUpdate = new CustomDataUpdate(this.log); CustomTransactionedOperation operation1 = new CustomTransactionedOperation(dataSet1); operation1.Execute += new Library.TransactionedOperationDelegate(customDataUpdate.UpdateData); // Hook data for second operation AggregateTransactionedOperation operation2 = new AggregateTransactionedOperation(dataSet2); operation2.Execute += new Library.TransactionedOperationDelegate(AggregateTransactionedOperation.SelfContainedUpdateData); // Collect together the operations and make them atomic Library.TransactionedOperation[] operations = new Library.TransactionedOperation[] {operation1, operation2}; transactionWrapper.MakeAtomic(operations); }
private ILog log = null; // Initialise this somewhere... #endregion Fields #region Methods /// <summary> /// /// </summary> /// <param name="dataSet"></param> public void UpdateCustomDetails(CustomDataSet dataSet) { IDbConnection connection = new System.Data.SqlClient.SqlConnection( /* Connection string goes here*/ ); Library.TransactionWrapper transactionWrapper = new Library.TransactionWrapper(connection); // Hook the data onto the operation parameters CustomDataUpdate customDataUpdate = new CustomDataUpdate(this.log); CustomTransactionedOperation operation = new CustomTransactionedOperation(dataSet); operation.Execute += new Library.TransactionedOperationDelegate(customDataUpdate.UpdateData); transactionWrapper.MakeAtomic(operation); }