Example #1
0
        /// <summary>
        /// Returns a list entities of type T.
        /// </summary>
        /// <param name="connection">Sql Connection</param>
        /// <param name="page">The page to return</param>
        /// <param name="pageSize">The number of records to return per page</param>
        /// <param name="adapter">ISqlAdapter for getting the sql statement</param>
        /// <param name="sql">The where clause</param>
        /// <param name="parameters">Parameters of the where clause</param>
        /// <param name="transaction">The transaction to run under, null (the default) if none</param>
        /// <param name="commandTimeout">Number of seconds before command execution timeout</param>
        /// <param name="fromCache">Cache the query.</param>
        /// <returns>True if records are deleted</returns>
        private static async Task <IPagedEnumerable <T> > GetPageListAsync <T>(this IDbConnection connection, int page, int pageSize, ISqlAdapter adapter, string sql, object parameters, IDbTransaction transaction = null, int?commandTimeout = null, bool fromCache = false) where T : class
        {
            var type      = typeof(T);
            var tinfo     = TableInfoCache(type);
            var selectSql = adapter.GetPageListQuery(tinfo, page, pageSize, sql);

            return(new PagedList <T>(
                       await connection.QueryAsync <T>(selectSql, parameters, transaction, commandTimeout: commandTimeout),
                       page,
                       pageSize,
                       await connection.CountAsync <T>(sql, parameters, transaction, commandTimeout: commandTimeout)
                       ));
        }