diff --git a/UnitOfWork/Collections/IQueryablePageListExtensions.cs b/UnitOfWork/Collections/IQueryablePageListExtensions.cs index 9578aae..a6f8f36 100644 --- a/UnitOfWork/Collections/IQueryablePageListExtensions.cs +++ b/UnitOfWork/Collections/IQueryablePageListExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -28,6 +29,18 @@ public static class IQueryablePageListExtensions } var count = await source.CountAsync(cancellationToken).ConfigureAwait(false); + + if (count == 0) + return new PagedList() + { + PageIndex = pageIndex, + PageSize = pageSize, + IndexFrom = indexFrom, + TotalCount = count, + Items = new List(), + TotalPages = 0 + }; + var items = await source.Skip((pageIndex - indexFrom) * pageSize) .Take(pageSize).ToListAsync(cancellationToken).ConfigureAwait(false);