| | |
| | | return connection; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// Dapper查询返回List<T> |
| | | /// Dapper查询返回List |
| | | /// </summary> |
| | | /// <typeparam name="T">需要返回的对象类型</typeparam> |
| | | /// <param name="sql">Sql语句</param> |
| | |
| | | } |
| | | } |
| | | |
| | | /// <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 |