B9_Pagination 1.1.0

dotnet add package B9_Pagination --version 1.1.0                
NuGet\Install-Package B9_Pagination -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="B9_Pagination" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add B9_Pagination --version 1.1.0                
#r "nuget: B9_Pagination, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install B9_Pagination as a Cake Addin
#addin nuget:?package=B9_Pagination&version=1.1.0

// Install B9_Pagination as a Cake Tool
#tool nuget:?package=B9_Pagination&version=1.1.0                

B9_Pagination

Version Downloads

Extensions for simple pagination

How to use?

You can use PaginationQuery model for set pagination parameter

var pagination = new PaginationQuery(pageNumber: 1, pageSize: 10);

var paginationResult = await items
    .Where(x => x.Id > 10)
    .GetPaginationAsync(pagination);

or set directly in method

var paginationResult = await items
    .Where(x => x.Id > 10)
    .GetPaginationAsync(pageNumber: 1, pageSize: 10);

Check out the sample project

You can use pagination in API endpoints

[HttpGet]
[ProducesResponseType(typeof(IPagination<GetShortAccountDto>), StatusCodes.Status200OK)]
public async Task<IActionResult> GetClientAccounts(
       [FromQuery] PaginationQuery pagination = default,
       [FromQuery] FilterDto filter = default,
       UserEnums.SortBy? sortBy = default,
       CancellationToken cancellationToken = default)
       => (await _accountService.GetAccountsAsync(pagination, filter, sortBy, cancellationToken)).ToActionResult();
What if you need to do something(Select,Where,GroupBy,etc) with the data before doing pagination?

You can use Pager<T> and manage validation yourself

var mappedItems = items
    .GroupBy(dto => dto.Name)
    .Select(g => new UserDto
    {
       Name = g.Key,
       Contacts = g.Select(dto => new UserContactDto
       {
          Email = dto.Email,
          Count = dto.Count
       })
     })
     .ToList();

var totalCount = mappedItems.Count();
var pager = new Pager<UserDto>(totalCount, pagination.PageNumber, pagination.PageSize);

if (!pager.IsValidPage)
       return pager.GetEmptyPagination();

return pager.GetPagination(mappedItems);

Additionaly if you need just map type you can use extension methods for map with AutoMapper GetPaginationWithMapAsync(this IQueryable<object> items, PaginationQuery pagination, IMapper mapper, CancellationToken cancellationToken = default) or GetPaginationWithMapAsync<TResult>(this IQueryable<object> items, PaginationQuery pagination, IConfigurationProvider configurationProvider, CancellationToken cancellationToken = default)

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 497 3/28/2022
1.0.2 462 12/10/2021
1.0.1 336 12/7/2021
1.0.0 389 10/18/2021