Friday, February 1, 2019

transactions in Entity Framework 6's code first approach to things

using (var transaction = _context.BeginTransaction())
{
   try
   {
      
DO WHAT NEEDS TO BE DONE HERE
      await _context.SaveChangesAsync();
      transaction.Commit();
   }
   catch (Exception ex)
   {
      transaction.Rollback();
      throw ex;
   }
}

 
 

Instead of .SaveChangesAsync() you may just have .SaveChanges() and I bet you can imagine the difference.

No comments:

Post a Comment