namespace CrazyStudio.Core.Common.Tools.Extensions
{
    public static class IQueryableExtensions
    {
        /// <summary>
        /// 分页
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static IQueryable<T> ToPage<T>(this IQueryable<T> query, int page, int pageSize)
        {
            //保证 搜索页面不小于 1
            page = Math.Max(page, 1);

            return query.Skip((page - 1) * pageSize).Take(pageSize);

        }
    }
}
