Skip to content

Commit 4a9c349

Browse files
authored
Merge pull request #339 from dncuug/dev
Add Entity Framework 6 (deprecated)
2 parents 4bb39c1 + 4c12488 commit 4a9c349

File tree

7 files changed

+161
-76
lines changed

7 files changed

+161
-76
lines changed

X.PagedList.sln

Lines changed: 0 additions & 72 deletions
This file was deleted.

X.PagedList.slnx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Solution>
2+
<Folder Name="/examples/">
3+
<Project Path="examples\Example.DAL\Example.DAL.csproj" />
4+
<Project Path="examples\Example.Website\Example.Website.csproj" />
5+
</Folder>
6+
<Folder Name="/src/">
7+
<Project Path="src\X.PagedList.EF\X.PagedList.EF.csproj" Type="Classic C#" />
8+
<Project Path="src\X.PagedList.EntityFramework\X.PagedList.EntityFramework.csproj" Type="Classic C#" />
9+
<Project Path="src\X.PagedList.Mvc.Core\X.PagedList.Mvc.Core.csproj" Type="Classic C#" />
10+
<Project Path="src\X.PagedList\X.PagedList.csproj" />
11+
<File Path="src\Directory.Build.props" />
12+
</Folder>
13+
<Folder Name="/tests/">
14+
<Project Path="tests\X.PagedList.Tests\X.PagedList.Tests.csproj" />
15+
</Folder>
16+
</Solution>

src/Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<Copyright>Andrew Gubskiy © 2025</Copyright>
1212
<Company>Ukrainian .NET Developer Community</Company>
1313

14-
<Version>10.5.8</Version>
15-
<AssemblyVersion>10.5.8</AssemblyVersion>
16-
<FileVersion>10.5.8</FileVersion>
17-
<PackageVersion>10.5.8</PackageVersion>
14+
<Version>10.5.9</Version>
15+
<AssemblyVersion>10.5.9</AssemblyVersion>
16+
<FileVersion>10.5.9</FileVersion>
17+
<PackageVersion>10.5.9</PackageVersion>
1818

1919
<RepositoryType>git</RepositoryType>
2020
<RepositoryUrl>https://github.com/dncuug/X.PagedList.git</RepositoryUrl>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.Entity;
4+
using System.Linq;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace X.PagedList.EntityFramework;
9+
10+
/// <summary>
11+
/// EntityFramework extension methods designed to simplify the creation of instances of <see cref="PagedList{T}"/>.
12+
/// </summary>
13+
public static class PagedListExtensions
14+
{
15+
/// <summary>
16+
/// Async creates a subset of this collection of objects that can be individually accessed by index and
17+
/// containing metadata about the collection of objects the subset was created from.
18+
/// </summary>
19+
/// <typeparam name="T">The type of object the collection should contain.</typeparam>
20+
/// <param name="superset">The collection of objects to be divided into subsets. If the collection implements <see cref="IQueryable{T}"/>, it will be treated as such.</param>
21+
/// <param name="pageNumber">The one-based index of the subset of objects to be contained by this instance.</param>
22+
/// <param name="pageSize">The maximum size of any individual subset.</param>
23+
/// <param name="totalSetCount">The total size of set</param>
24+
/// <param name="cancellationToken"></param>
25+
/// <returns>
26+
/// A subset of this collection of objects that can be individually accessed by index and containing metadata
27+
/// about the collection of objects the subset was created from.
28+
/// </returns>
29+
/// <seealso cref="PagedList{T}"/>
30+
public static async Task<IPagedList<T>> ToPagedListAsync<T>(this IQueryable<T> superset, int pageNumber, int pageSize, int? totalSetCount, CancellationToken cancellationToken)
31+
{
32+
if (superset == null)
33+
{
34+
throw new ArgumentNullException(nameof(superset));
35+
}
36+
37+
if (pageNumber < 1)
38+
{
39+
throw new ArgumentOutOfRangeException($"pageNumber = {pageNumber}. PageNumber cannot be below 1.");
40+
}
41+
42+
if (pageSize < 1)
43+
{
44+
throw new ArgumentOutOfRangeException($"pageSize = {pageSize}. PageSize cannot be less than 1.");
45+
}
46+
47+
List<T> subset;
48+
int totalCount;
49+
50+
if (totalSetCount.HasValue)
51+
{
52+
totalCount = totalSetCount.Value;
53+
}
54+
else
55+
{
56+
totalCount = await superset
57+
.CountAsync(cancellationToken: cancellationToken)
58+
.ConfigureAwait(false);
59+
}
60+
61+
if (totalCount > 0)
62+
{
63+
int skip = (pageNumber - 1) * pageSize;
64+
65+
subset = await superset
66+
.Skip(skip)
67+
.Take(pageSize)
68+
.ToListAsync(cancellationToken)
69+
.ConfigureAwait(false);
70+
}
71+
else
72+
{
73+
subset = new List<T>();
74+
}
75+
76+
return new StaticPagedList<T>(subset, pageNumber, pageSize, totalCount);
77+
}
78+
79+
/// <summary>
80+
/// Async creates a subset of this collection of objects that can be individually accessed by index and
81+
/// containing metadata about the collection of objects the subset was created from.
82+
/// </summary>
83+
/// <typeparam name="T">The type of object the collection should contain.</typeparam>
84+
/// <param name="superset">The collection of objects to be divided into subsets. If the collection implements <see cref="IQueryable{T}"/>, it will be treated as such.</param>
85+
/// <param name="pageNumber">The one-based index of the subset of objects to be contained by this instance.</param>
86+
/// <param name="pageSize">The maximum size of any individual subset.</param>
87+
/// <param name="totalSetCount">The total size of set</param>
88+
/// <returns>
89+
/// A subset of this collection of objects that can be individually accessed by index and containing metadata
90+
/// about the collection of objects the subset was created from.
91+
/// </returns>
92+
/// <seealso cref="PagedList{T}"/>
93+
public static Task<IPagedList<T>> ToPagedListAsync<T>(this IQueryable<T> superset, int pageNumber, int pageSize, int? totalSetCount = null)
94+
{
95+
return ToPagedListAsync(superset, pageNumber, pageSize, totalSetCount, CancellationToken.None);
96+
}
97+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# X.Extensions.PagedList.EF6
2+
3+
[![NuGet Version](http://img.shields.io/nuget/v/X.PagedList.EntityFramework.svg?style=flat)](https://www.nuget.org/packages/X.PagedList.EntityFramework/)
4+
[![Twitter URL](https://img.shields.io/twitter/url/https/x.com/andrew_gubskiy.svg?style=social&label=Follow%20me!)](https://x.com/intent/user?screen_name=andrew_gubskiy)
5+
6+
7+
## What is this?
8+
The X.PagedList.EntityFramework library provides Entity Framework (Version 6) extensions for the X.PagedList library,
9+
enabling easier paging through data collections within Entity Framework contexts. This extension facilitates the
10+
creation of paged lists from IQueryable collections, streamlining the process of managing large datasets
11+
in .NET applications.
12+
13+
## How to use
14+
You can find all information about how to use X.PagedList libraries in [Wiki](https://github.com/dncuug/X.PagedList/wiki)
15+
16+
## Get a digital subscription for project news
17+
[Subscribe](https://x.com/intent/user?screen_name=andrew_gubskiy) to my X to keep up-to-date with project news and receive announcements.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Title>X.PagedList.EntityFramework</Title>
5+
<Description>Entity Framework 6 (legacy) extensions for X.PagedList library</Description>
6+
<LangVersion>default</LangVersion>
7+
<TargetFrameworks>net481;netstandard2.1;</TargetFrameworks>
8+
<PackageTags>paging pagedlist paged list entity framework ef6</PackageTags>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<None Include="README.md" Pack="true" PackagePath=""/>
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Include="../../LICENSE.md" Pack="true" PackagePath=""/>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<PackageReference Include="EntityFramework" Version="[6.5.1,7.0.0)" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\X.PagedList\X.PagedList.csproj"/>
25+
</ItemGroup>
26+
27+
</Project>
596 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)