using (var transaction = new System.Transactions.TransactionScope())
{
// DBC = Database Command
// create the database context
var database = new DatabaseContext();
// search for the user with id #1
// DBC: BEGIN TRANSACTION
// DBC: select * from [User] where Id = 1
var userA = database.Users.Find(1);
// DBC: select * from [User] where Id = 2
var userB = database.Users.Find(2);
userA.Name = "Admin";
// DBC: update User set Name = "Admin" where Id = 1
database.SaveChanges();
userB.Age = 28;
// DBC: update User set Age = 28 where Id = 2
database.SaveChanges();
// DBC: COMMIT TRANSACTION
transaction.Complete();
}
// DBC = Database Command
// create the database context
var database = new DatabaseContext();
// search for the user with id #1
// DBC: select * from [User] where Id = 1
var userA = database.Users.Find(1);
// DBC: select * from [User] where Id = 2
var userB = database.Users.Find(2);
userA.Name = "Admin";
userB.Age = 28;
// DBC: BEGIN TRANSACTION
// DBC: update User set Name = "Admin" where Id = 1
// DBC: update User set Age = 28 where Id = 2
// DBC: COMMIT TRANSACTION
database.SaveChanges();