using (var scope = new TransactionScope()) { using (var db1 = new Database1Entities()) { db1.Table1.Add(new Table1 { Column1 = "Value1" }); db1.SaveChanges(); } using (var db2 = new Database2Entities()) { db2.Table2.Add(new Table2 { Column2 = "Value2" }); db2.SaveChanges(); } scope.Complete(); }
using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { // Perform transactional work here scope.Complete(); }This example demonstrates the use of TransactionScopeAsyncFlowOption, which enables asynchronous code to participate in a transaction. It is used to ensure that the transaction context flows with the asynchronous call. Package Library: The System.Transactions namespace in the .NET Framework provides the TransactionScope class and other classes that are needed to work with transactions.