using (var scope = new TransactionScope()) { // transactional code block here scope.Complete(); // commit the transaction }
using var scope = new TransactionScope(TransactionScopeOption.Required); // transactional code block here scope.Complete(); // commit the transactionThis code creates a new `TransactionScope` with the `TransactionScopeOption.Required` option. This means that if a transaction already exists, the new code block will participate in that transaction. If no transaction exists, a new one will be created. Package Library: `System.Transactions.TransactionScope` is a part of the .NET Framework Class Library.