Esempio n. 1
0
        /// <summary>
        /// Executes a query, returning the data typed as per T.
        /// For details, refer to the document of Dapper.
        /// </summary>
        /// <typeparam name="T">Result type.</typeparam>
        /// <param name="cnn">Connection.</param>
        /// <param name="sql">Sql.</param>
        /// <param name="transaction">Transactions to be executed at the data source.</param>
        /// <param name="commandTimeout">Command timeout.</param>
        /// <param name="commandType">Command type.</param>
        /// <returns>
        ///     A sequence of data of the supplied type; if a basic type (int, string, etc) is
        ///     queried then the data from the first column in assumed, otherwise an instance
        ///     is created per row, and a direct column-name===member-name mapping is assumed
        ///     (case insensitive).
        /// </returns>
        public static Task <IEnumerable <T> > QueryAsync <T>(this IDbConnection cnn, BuildedSql sql, IDbTransaction transaction = null, int?commandTimeout = default(int?), CommandType?commandType = default(CommandType?))
        {
            //for testing.
            if (DapperAdapterTestPlugin.Query != null)
            {
                return(Task.Factory.StartNew(() => (IEnumerable <T>) new T[DapperAdapterTestPlugin.Query(cnn, sql)]));
            }

            //debug.
            Debug(sql);

            try
            {
                var ret = DapperWrapperAsync <T> .Query(cnn, sql.Text, CreateDynamicParam(sql.GetParams()), transaction, commandTimeout, commandType);

                ResultLog?.Invoke(ret);
                return(ret);
            }
            catch (Exception e)
            {
                throw GetCoreException(e);
            }
        }
        /// <summary>
        /// Executes a query, returning the data typed as per T.
        /// For details, refer to the document of Dapper.
        /// </summary>
        /// <typeparam name="T">Result type.</typeparam>
        /// <param name="cnn">Connection.</param>
        /// <param name="sql">Sql.</param>
        /// <param name="transaction">Transactions to be executed at the data source.</param>
        /// <param name="buffered">Is buffered,</param>
        /// <param name="commandTimeout">Command timeout.</param>
        /// <param name="commandType">Command type.</param>
        /// <returns>
        ///     A sequence of data of the supplied type; if a basic type (int, string, etc) is
        ///     queried then the data from the first column in assumed, otherwise an instance
        ///     is created per row, and a direct column-name===member-name mapping is assumed
        ///     (case insensitive).
        /// </returns>
        public static IEnumerable <T> Query <T>(this IDbConnection cnn, BuildedSql sql, IDbTransaction transaction = null, bool buffered = true, int?commandTimeout = default(int?), CommandType?commandType = default(CommandType?))
        {
            //for testing.
            if (DapperAdapterTestPlugin.Query != null)
            {
                return(new T[DapperAdapterTestPlugin.Query(cnn, sql)]);
            }

            //debug.
            Debug(sql);

            try
            {
                var ret = DapperWrapper <T> .Query(cnn, sql.Text, CreateDynamicParam(sql.GetParams()), transaction, buffered, commandTimeout, commandType);

                ResultLog?.Invoke(ret);
                return(ret);
            }
            catch (Exception e)
            {
                throw GetCoreException(e);
            }
        }