-
-
Save njmube/3af7d18ebff96041136e 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