Last active
August 29, 2015 14:18
-
-
Save jbogard/e2926bedb1ab8d5786eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public void Txn(Action<MyContext> action) | |
{ | |
var dbContext = new MyContext(); | |
DbContextTransaction txn = null; | |
try | |
{ | |
txn = dbContext.Database.BeginTransaction(); | |
action(dbContext); | |
dbContext.SaveChanges(); | |
txn.Commit(); | |
} | |
catch (Exception) | |
{ | |
txn?.Rollback(); | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment