public static void SelfContainedUpdateData(Library.TransactionWrapper sender, Library.TransactionArgs args) { // TODO: Paramter checks AggregateTransactionedOperation operation = args.Operation as AggregateTransactionedOperation; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Transaction = args.Transaction as System.Data.SqlClient.SqlTransaction; sqlCommand.Connection = args.Connection as System.Data.SqlClient.SqlConnection; sqlCommand.CommandText = ""; /* Some suitable text here */ sqlCommand.ExecuteNonQuery(); }
/// <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); }