示例#1
0
 public static void ExecuteInTransaction(this DatabaseContext context, IsolationLevel isolationLevel, Action act)
 {
     using (var transaction = context.BeginTransaction(isolationLevel))
     {
         try
         {
             act.Invoke();
             context.SaveChanges();
             transaction.Commit();
         }
         catch (Exception ex)
         {
             transaction.Rollback();
             throw ex;
         }
     }
 }
示例#2
0
 public static T ExecuteInTransaction <T>(this DatabaseContext context, IsolationLevel isolationLevel, Func <T> act)
 {
     using (var transaction = context.BeginTransaction(isolationLevel))
     {
         try
         {
             var result = act.Invoke();
             context.SaveChanges();
             transaction.Commit();
             return(result);
         }
         catch (Exception ex)
         {
             transaction.Rollback();
             throw ex;
         }
     }
 }