dncuug / X.PagedList

Library for easily paging through any IEnumerable/IQueryable in ASP.NET
https://andrew.gubskiy.com/open-source
MIT License
899 stars 213 forks source link

Nuget version does not seem to refect the changes in Master #223

Closed teghoz closed 1 year ago

teghoz commented 1 year ago

I just installed the core version 8.4.3 and looking at the internals i see this:

public static async Task<IPagedList<T>> ToPagedListAsync<T>(this IQueryable<T> superset, int pageNumber, int pageSize, CancellationToken cancellationToken)
        {
            if (pageNumber < 1)
            {
                DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(44, 1);
                defaultInterpolatedStringHandler.AppendLiteral("pageNumber = ");
                defaultInterpolatedStringHandler.AppendFormatted(pageNumber);
                defaultInterpolatedStringHandler.AppendLiteral(". PageNumber cannot be below 1.");
                throw new ArgumentOutOfRangeException(defaultInterpolatedStringHandler.ToStringAndClear());
            }

            if (pageSize < 1)
            {
                DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(44, 1);
                defaultInterpolatedStringHandler.AppendLiteral("pageSize = ");
                defaultInterpolatedStringHandler.AppendFormatted(pageSize);
                defaultInterpolatedStringHandler.AppendLiteral(". PageSize cannot be less than 1.");
                throw new ArgumentOutOfRangeException(defaultInterpolatedStringHandler.ToStringAndClear());
            }

            List<T> subset = new List<T>();
            int totalCount = 0;
            if (superset != null)
            {
                totalCount = superset.Count();
                if (totalCount > 0)
                {
                    List<T> list = subset;
                    List<T> collection = ((pageNumber != 1) ? (await superset.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToListAsync(cancellationToken)
                        .ConfigureAwait(continueOnCapturedContext: false)) : (await superset.Skip(0).Take(pageSize).ToListAsync(cancellationToken)
                        .ConfigureAwait(continueOnCapturedContext: false)));
                    list.AddRange(collection);
                }
            }

            return new StaticPagedList<T>(subset, pageNumber, pageSize, totalCount);
        }

I was worried about the line totalCount = superset.Count(); then I check the master branch to see this:

public static async Task<IPagedList<T>> ToPagedListAsync<T>(this IQueryable<T> superset, int pageNumber, int pageSize, CancellationToken cancellationToken)
    {
        if (pageNumber < 1)
        {
            throw new ArgumentOutOfRangeException($"pageNumber = {pageNumber}. PageNumber cannot be below 1.");
        }

        if (pageSize < 1)
        {
            throw new ArgumentOutOfRangeException($"pageSize = {pageSize}. PageSize cannot be less than 1.");
        }

        var subset = new List<T>();
        var totalCount = 0;

        if (superset != null)
        {
            totalCount = await superset.CountAsync(cancellationToken).ConfigureAwait(false);
            if (totalCount > 0)
            {
                subset.AddRange(
                    (pageNumber == 1)
                        ? await superset.Skip(0).Take(pageSize).ToListAsync(cancellationToken).ConfigureAwait(false)
                        : await superset.Skip(((pageNumber - 1) * pageSize)).Take(pageSize).ToListAsync(cancellationToken).ConfigureAwait(false)
                );
            }
        }

        return new StaticPagedList<T>(subset, pageNumber, pageSize, totalCount);
    }

Am I missing something?

plittlewood-rpt commented 1 year ago

Master branch doesn't currently build due to this change. There hasn't been a new release of this package since May 2022

teghoz commented 1 year ago

Master branch doesn't currently build due to this change. There hasn't been a new release of this package since May 2022

I raised a fix for it. Its awaiting approval

plittlewood-rpt commented 1 year ago

Hey @teghoz - For me I've downloaded a fresh copy of master and opened it and tried to build it. I get

'IQueryable<T>' does not contain a definition for 'CountAsync' and no accessible extension method 'CountAsync' accepting a first argument of type 'IQueryable<T>' could be found (are you missing a using directive or an assembly reference?)

We're having issues in our APIs with the Count() not being async in the version we are using so trying to figure out where I'm going wrong!

a-gubskiy commented 1 year ago

Master branch and nugget version was synced.