Saturday, March 2, 2019

an example of a transaction around a data context in Entity Framework 6's code first way of doing things

using (var transaction = _myContext.BeginTransaction()) {
   try {
      cheese.type = type;
      cheese.percentage = 100;
      await UpdateCheese(foo);
      tacos[0] = await AssociateCheeseToTacos(foo);
      transaction.Commit();
   }
   catch (Exception ex) {
      transaction.Rollback();
      throw ex;
   }
}

No comments:

Post a Comment