-
-
Save SeriousM/e6b30db2b21e7e602655 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment