Пример #1
0
 public int SaveChanges()
 {
     using (TransactionScope transactionScope = new TransactionScope())
     {
         try
         {
             _context.SaveChanges();
             transactionScope.Complete();
             return(1);
         }
         catch (Exception ex)
         {
             this._logger.LogError("方法:SaveChanges" + "错误信息:" + ex.Message);
             return(0);
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 执行事务
        /// </summary>
        /// <param name="dbcontext">装载数据后的Context</param>
        /// <returns>true成功,false失败</returns>
        public bool ExecuteTransaction(NCSContext dbcontext, ref string Msg)
        {
            using (var tran = dbcontext.Database.BeginTransaction())
            {
                try
                {
                    dbcontext.SaveChanges();
                    tran.Commit();

                    Flag = true;
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    Flag = false;
                    Msg  = ex.Message;
                }
                return(Flag);
            }
        }