yl
2022-07-08 350aef928584da9bb91d2de8646ce42e1f5758c1
VueWebApi/Tools/DapperHelper.cs
@@ -29,8 +29,9 @@
            return connection;
        }
        /// <summary>
        /// Dapper查询返回List<T>
        /// Dapper查询返回List
        /// </summary>
        /// <typeparam name="T">需要返回的对象类型</typeparam>
        /// <param name="sql">Sql语句</param>
@@ -374,6 +375,42 @@
            }
        }
        /// <summary>
        /// 增加,删除,修改使用的 事务方法  Sqllist为依次执行
        /// </summary>
        /// <param name="sqlList"></param>
        /// <returns></returns>
        public static int DoTransactionCont(List<object> sqlList)
        {
            int result = 0;
            IDbTransaction tranction = null;
            using (IDbConnection conn = sqlConnection())
            {
                try
                {
                    tranction = conn.BeginTransaction();
                    for (int i = 0; i < sqlList.Count; i++)
                    {
                        result += conn.Execute(sqlList[i].GetType().GetProperty("str").GetValue(sqlList[i], null).ToString(), sqlList[i].GetType().GetProperty("parm").GetValue(sqlList[i], null), tranction);
                    }
                    tranction.Commit();
                }
                catch (Exception ex)
                {
                    //创建日志记录组件实例
                    LogHelper.WriteLog(ex);
                    tranction.Rollback();
                    throw ex;
                }
                finally
                {
                    conn.Dispose();
                    conn.Close();
                }
                return result;
            }
        }
        /// <summary>
        /// Dapper插入 返回自增主键Id