コード例 #1
0
        /// <summary>
        /// 异步查询记录数
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="connection"></param>
        /// <param name="param"></param>
        /// <param name="predicate"></param>
        /// <param name="transaction"></param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        public static Task <int> CountAsync <TEntity>(this IDbConnection connection, object param  = null,
                                                      Expression <Func <TEntity, bool> > predicate = null,
                                                      IDbTransaction transaction = null, int?commandTimeout = null)
            where TEntity : BaseEntity
        {
            ISqlAdapter adapter = GetSqlAdapter(connection);

            var sql = adapter.GetCount(predicate);

            if (param == null)
            {
                param = adapter.ParamValues;
            }

            var result = connection.ExecuteScalarAsyncExt <int>(sql, param, transaction, commandTimeout);

            return(result);
        }