/// <inheritdoc /> public void StartBatch(long threadOrBatchId, string transactionName = null) { if (this.BatchConnections.ContainsKey(threadOrBatchId)) { throw new Exception("Batch is already running on this thread/batch id."); } var connection = new SqlConnection(ConnectionString); connection.Open(); BatchConnections.Add(threadOrBatchId, connection); if (transactionName != null) { this.Transactions.Add(threadOrBatchId, connection.BeginTransaction(transactionName)); } }
/// <inheritdoc /> public void EndBatch(long threadOrBatchId) { if (!this.BatchConnections.ContainsKey(threadOrBatchId)) { return; // no batch } var connection = BatchConnections[threadOrBatchId]; BatchConnections.Remove(threadOrBatchId); if (Transactions.ContainsKey(threadOrBatchId)) { Transactions[threadOrBatchId].Commit(); Transactions.Remove(threadOrBatchId); } connection.Dispose(); }