Exemplo n.º 1
0
        async Task <IEnumerable <TReturn> > QueryMap <TReturn>(
            string p_keyOrSql,
            Type[] p_types,
            Func <object[], TReturn> p_map,
            object p_params,
            bool p_deferred,
            string p_splitOn)
        {
            string sql = Kit.Sql(p_keyOrSql);

            try
            {
                await OpenConnection();

                var result = await _conn.QueryAsync(sql, p_types, p_map, p_params, _tran, !p_deferred, p_splitOn);

                return(result);
            }
            catch (Exception ex)
            {
                throw GetSqlException(CreateCommand(p_keyOrSql, p_params, p_deferred), ex);
            }
            finally
            {
                ReleaseConnection();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建Dapper的命令定义
        /// </summary>
        /// <param name="p_keyOrSql"></param>
        /// <param name="p_params"></param>
        /// <param name="p_deferred"></param>
        /// <returns></returns>
        CommandDefinition CreateCommand(string p_keyOrSql, object p_params, bool p_deferred)
        {
            string sql = Kit.Sql(p_keyOrSql);

            if (TraceSql)
            {
                Log.Information(BuildSql(sql, p_params));
            }

            return(new CommandDefinition(
                       Kit.Sql(p_keyOrSql),
                       p_params,
                       _tran,
                       null,
                       null,
                       p_deferred ? CommandFlags.Pipelined : CommandFlags.Buffered,
                       default(CancellationToken)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 按页查询数据
        /// </summary>
        /// <param name="p_starRow">起始行号:mysql中第一行为0行</param>
        /// <param name="p_pageSize">每页显示行数</param>
        /// <param name="p_keyOrSql">Sql字典中的键名(无空格) 或 Sql语句</param>
        /// <param name="p_params">参数值,支持Dict或匿名对象,默认null</param>
        /// <returns>返回Table数据</returns>
        public Task <Table> GetPage(int p_starRow, int p_pageSize, string p_keyOrSql, object p_params = null)
        {
            string sql = $"select * from ({Kit.Sql(p_keyOrSql)}) a limit {p_starRow},{p_pageSize} ";

            return(new MySqlAccess().Query(sql, p_params));
        }