Skip to content

Commit

Permalink
fix: fix the arch#58 issues
Browse files Browse the repository at this point in the history
PagedList check the IEnumerable<T> whether is IQuerable<T>

close arch#58
  • Loading branch information
yingtingxu committed Feb 5, 2018
1 parent e94c812 commit 50ccab0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Host/Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.1" />
Expand Down
54 changes: 41 additions & 13 deletions src/Microsoft.EntityFrameworkCore.UnitOfWork/PagedList/PagedList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,26 @@ internal PagedList(IEnumerable<T> source, int pageIndex, int pageSize, int index
throw new ArgumentException($"indexFrom: {indexFrom} > pageIndex: {pageIndex}, must indexFrom <= pageIndex");
}

PageIndex = pageIndex;
PageSize = pageSize;
IndexFrom = indexFrom;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
if (source is IQueryable<T> querable)
{
PageIndex = pageIndex;
PageSize = pageSize;
IndexFrom = indexFrom;
TotalCount = querable.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);

Items = querable.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToList();
}
else
{
PageIndex = pageIndex;
PageSize = pageSize;
IndexFrom = indexFrom;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);

Items = source.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToList();
Items = source.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToList();
}
}

/// <summary>
Expand Down Expand Up @@ -152,15 +165,30 @@ public PagedList(IEnumerable<TSource> source, Func<IEnumerable<TSource>, IEnumer
throw new ArgumentException($"indexFrom: {indexFrom} > pageIndex: {pageIndex}, must indexFrom <= pageIndex");
}

PageIndex = pageIndex;
PageSize = pageSize;
IndexFrom = indexFrom;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
if (source is IQueryable<TSource> querable)
{
PageIndex = pageIndex;
PageSize = pageSize;
IndexFrom = indexFrom;
TotalCount = querable.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);

var items = source.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToArray();
var items = querable.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToArray();

Items = new List<TResult>(converter(items));
Items = new List<TResult>(converter(items));
}
else
{
PageIndex = pageIndex;
PageSize = pageSize;
IndexFrom = indexFrom;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);

var items = source.Skip((PageIndex - IndexFrom) * PageSize).Take(PageSize).ToArray();

Items = new List<TResult>(converter(items));
}
}

/// <summary>
Expand Down

0 comments on commit 50ccab0

Please sign in to comment.