From ce6506871a3d84368d3fcdae00cc791068adcc88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Wed, 23 Oct 2024 14:57:09 +0200 Subject: [PATCH] New project X.PagedList.EF6 Added compatibility package for Entity Framework version 6. --- X.PagedList.sln | 7 ++ src/X.PagedList.EF6/PagedListExtensions.cs | 99 +++++++++++++++++++++ src/X.PagedList.EF6/README.md | 16 ++++ src/X.PagedList.EF6/X.PagedList.EF6.csproj | 29 ++++++ src/X.PagedList.EF6/xpagedlist.snk | Bin 0 -> 596 bytes src/X.PagedList/X.PagedList.csproj | 2 +- 6 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/X.PagedList.EF6/PagedListExtensions.cs create mode 100644 src/X.PagedList.EF6/README.md create mode 100644 src/X.PagedList.EF6/X.PagedList.EF6.csproj create mode 100644 src/X.PagedList.EF6/xpagedlist.snk diff --git a/X.PagedList.sln b/X.PagedList.sln index ac50aa9c..4f1ff1df 100644 --- a/X.PagedList.sln +++ b/X.PagedList.sln @@ -24,6 +24,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X.PagedList.Mvc.Core", "src EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "X.PagedList.EF", "src\X.PagedList.EF\X.PagedList.EF.csproj", "{B72170CA-12E0-46E5-821C-FCE7E6F79736}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "X.PagedList.EF6", "src\X.PagedList.EF6\X.PagedList.EF6.csproj", "{BFFDE538-C911-46B4-ACE8-B4702ACCC6A5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -54,6 +56,10 @@ Global {B72170CA-12E0-46E5-821C-FCE7E6F79736}.Debug|Any CPU.Build.0 = Debug|Any CPU {B72170CA-12E0-46E5-821C-FCE7E6F79736}.Release|Any CPU.ActiveCfg = Release|Any CPU {B72170CA-12E0-46E5-821C-FCE7E6F79736}.Release|Any CPU.Build.0 = Release|Any CPU + {BFFDE538-C911-46B4-ACE8-B4702ACCC6A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BFFDE538-C911-46B4-ACE8-B4702ACCC6A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BFFDE538-C911-46B4-ACE8-B4702ACCC6A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BFFDE538-C911-46B4-ACE8-B4702ACCC6A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -65,6 +71,7 @@ Global {AD16A8D1-EAF0-4947-BCEC-A8B423B2F117} = {309A8FC8-4784-4D8D-903F-BD54EBB0F1D7} {3B840A44-3150-4BB5-83DA-9B81D1FCB6BE} = {BDDADD09-D112-418E-8469-BC762EC09936} {B72170CA-12E0-46E5-821C-FCE7E6F79736} = {BDDADD09-D112-418E-8469-BC762EC09936} + {BFFDE538-C911-46B4-ACE8-B4702ACCC6A5} = {BDDADD09-D112-418E-8469-BC762EC09936} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1A82D446-6F26-48B2-8085-DFA5F87453FC} diff --git a/src/X.PagedList.EF6/PagedListExtensions.cs b/src/X.PagedList.EF6/PagedListExtensions.cs new file mode 100644 index 00000000..084df486 --- /dev/null +++ b/src/X.PagedList.EF6/PagedListExtensions.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using JetBrains.Annotations; + +namespace X.PagedList.EF; + +/// +/// EntityFramework extension methods designed to simplify the creation of instances of . +/// +[PublicAPI] +public static class PagedListExtensions +{ + /// + /// Async creates a subset of this collection of objects that can be individually accessed by index and + /// containing metadata about the collection of objects the subset was created from. + /// + /// The type of object the collection should contain. + /// The collection of objects to be divided into subsets. If the collection implements , it will be treated as such. + /// The one-based index of the subset of objects to be contained by this instance. + /// The maximum size of any individual subset. + /// The total size of set + /// + /// + /// A subset of this collection of objects that can be individually accessed by index and containing metadata + /// about the collection of objects the subset was created from. + /// + /// + public static async Task> ToPagedListAsync(this IQueryable superset, int pageNumber, int pageSize, int? totalSetCount, CancellationToken cancellationToken) + { + if (superset == null) + { + throw new ArgumentNullException(nameof(superset)); + } + + 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."); + } + + List subset; + int totalCount; + + if (totalSetCount.HasValue) + { + totalCount = totalSetCount.Value; + } + else + { + totalCount = await superset + .CountAsync(cancellationToken: cancellationToken) + .ConfigureAwait(false); + } + + if (totalCount > 0) + { + int skip = (pageNumber - 1) * pageSize; + + subset = await superset + .Skip(skip) + .Take(pageSize) + .ToListAsync(cancellationToken) + .ConfigureAwait(false); + } + else + { + subset = new List(); + } + + return new StaticPagedList(subset, pageNumber, pageSize, totalCount); + } + + /// + /// Async creates a subset of this collection of objects that can be individually accessed by index and + /// containing metadata about the collection of objects the subset was created from. + /// + /// The type of object the collection should contain. + /// The collection of objects to be divided into subsets. If the collection implements , it will be treated as such. + /// The one-based index of the subset of objects to be contained by this instance. + /// The maximum size of any individual subset. + /// The total size of set + /// + /// A subset of this collection of objects that can be individually accessed by index and containing metadata + /// about the collection of objects the subset was created from. + /// + /// + public static Task> ToPagedListAsync(this IQueryable superset, int pageNumber, int pageSize, int? totalSetCount = null) + { + return ToPagedListAsync(superset, pageNumber, pageSize, totalSetCount, CancellationToken.None); + } +} diff --git a/src/X.PagedList.EF6/README.md b/src/X.PagedList.EF6/README.md new file mode 100644 index 00000000..538cd9fd --- /dev/null +++ b/src/X.PagedList.EF6/README.md @@ -0,0 +1,16 @@ +# X.Extensions.PagedList.EF + +[![NuGet Version](http://img.shields.io/nuget/v/X.PagedList.EF6.svg?style=flat)](https://www.nuget.org/packages/X.PagedList.EF6/) +[![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) + + +## What is this? +The X.PagedList.EF6 library provides Entity Framework (Version 6) extensions for the X.PagedList library, enabling easier +paging through data collections within Entity Framework contexts. This extension facilitates the creation of paged +lists from IQueryable collections, streamlining the process of managing large datasets in .NET applications. + +## How to use +You can find all information about how to use X.PagedList libraries in [Wiki](https://github.com/dncuug/X.PagedList/wiki) + +## Get a digital subscription for project news +[Subscribe](https://x.com/intent/user?screen_name=andrew_gubskiy) to my X to keep up-to-date with project news and receive announcements. \ No newline at end of file diff --git a/src/X.PagedList.EF6/X.PagedList.EF6.csproj b/src/X.PagedList.EF6/X.PagedList.EF6.csproj new file mode 100644 index 00000000..e95ff370 --- /dev/null +++ b/src/X.PagedList.EF6/X.PagedList.EF6.csproj @@ -0,0 +1,29 @@ + + + + X.PagedList.EF6 + EF6 (legacy) extensions for X.PagedList library + default + X.PagedList.EF + net481;netstandard2.1; + paging pagedlist paged list entity framework ef6 + + + + + + + + + + + + + + + + + + + + diff --git a/src/X.PagedList.EF6/xpagedlist.snk b/src/X.PagedList.EF6/xpagedlist.snk new file mode 100644 index 0000000000000000000000000000000000000000..194febd5b9194088df89750fa66d4c677edb51a5 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50096wc|V`+yT!};12px7HCvAZy0(liF2HQC zOuN&#J_qPG$;s+?jHoZ-F)M)u0Te-hoiWLYD@{ryOTaS1u_djJ&Xtb;eEy{d6+H$q zQk6z_tcr?V2lG;N6Ze+FiE5)mY(@VDZ^uRtr+w!H4Ty!DNk3I)=l%^@zb(c24j8Ma zeqMsKHSMHKFE?PieF}K4tL035#s|e9jhRJZC4iQ*xMt1*Qup30n@0rt|5xO3-vqdko}A$kv}-6s|Gf`*Ab{_a zn~8kPt?>o52bJ2*8V|(|z;m^OC8Wc3M+!4jYs7TgGR9uX% z-ve9cr3jdr8_!JofP>!{#@s|TwebNNfG5pp*RY%mALmp6Xh|qSHV45{e*SM0z+xW$ zHBnx2k~2+O6DJBFVa&%AfN1Pdv*o=yupI?mwLibrary for easily paging through any IEnumerable/IQueryable in .NET default - net6.0;net7.0;net8.0;netstandard2.0;netstandard2.1 + net481;net6.0;net7.0;net8.0;netstandard2.0;netstandard2.1 paging pagedlist paged list