Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ozakboy/ozakboy.pagedata
A lightweight and flexible pagination library for .NET applications, supporting List<T>, IQueryable<T>, and IEnumerable<T> with easy-to-use extension methods.
https://github.com/ozakboy/ozakboy.pagedata
csharp dotnet ef-core library linq net6 net7 net8 netcore nuget pagination pagination-library
Last synced: 1 day ago
JSON representation
A lightweight and flexible pagination library for .NET applications, supporting List<T>, IQueryable<T>, and IEnumerable<T> with easy-to-use extension methods.
- Host: GitHub
- URL: https://github.com/ozakboy/ozakboy.pagedata
- Owner: ozakboy
- License: mit
- Created: 2022-03-27T06:31:50.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-23T09:28:40.000Z (2 months ago)
- Last Synced: 2024-12-23T13:40:48.520Z (about 1 month ago)
- Topics: csharp, dotnet, ef-core, library, linq, net6, net7, net8, netcore, nuget, pagination, pagination-library
- Language: C#
- Homepage: https://www.nuget.org/packages/Ozakboy.PageData
- Size: 818 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ozakboy.PageData
[![nuget](https://img.shields.io/badge/nuget-ozakboy.PageData-blue)](https://www.nuget.org/packages/Ozakboy.PageData/)
[![github](https://img.shields.io/badge/github-ozakboy.PageData-blue)](https://github.com/ozakboy/ozakboy.PageData)[English](README.md) | [繁體中文](README_zh-TW.md)
A lightweight and flexible pagination library for .NET applications. Easily implement pagination functionality in your applications with support for various data sources including Lists, IQueryable, and IEnumerable.
## Features
- Simple and intuitive pagination implementation
- Support for multiple data source types (List, IQueryable, IEnumerable)
- Flexible page size configuration
- Complete paging information
- Data transformation support
- Extension methods for easy integration
- Compatible with Entity Framework Core queries## Installation
Install via NuGet Package Manager:
```bash
Install-Package Ozakboy.PageData
```Or via .NET CLI:
```bash
dotnet add package Ozakboy.PageData
```## Supported Frameworks
- .NET 6.0
- .NET 7.0
- .NET 8.0## Core Components
### 1. PageInfo
Contains basic pagination information:
- Current page number
- Items per page (Limit)
- Total items count
- Total pages### 2. VPageData
Generic class that holds:
- Paginated data (List)
- Page information (PageInfo)### 3. ASearchPageInfo
Abstract base class for search parameters:
- Base page number property
- Default limit (items per page) property## Usage Examples
### Basic Usage
```csharp
using Ozakboy.PageData;// With List
var myList = new List() { "item1", "item2", "item3", ... };
var pagedResult = myList.ToPageData(page: 1, limit: 10);// With IQueryable (e.g., Entity Framework)
var query = dbContext.Users.Where(u => u.IsActive);
var pagedUsers = query.ToPageData(page: 1, limit: 10);// With IEnumerable
IEnumerable products = GetProducts();
var pagedProducts = products.ToPageData(page: 1, limit: 10);
```### With Data Transformation
```csharp
var pagedResult = query.ToPageData(1, 10)
.Select(user => new UserDto
{
Id = user.Id,
Name = user.Name
});
```### Custom Search Parameters
```csharp
public class UserSearchParams : ASearchPageInfo
{
public string? SearchName { get; set; }
public bool? IsActive { get; set; }
}// Usage
var searchParams = new UserSearchParams
{
Page = 1,
Limit = 10,
SearchName = "John"
};
```### Accessing Page Information
```csharp
var result = query.ToPageData(1, 10);Console.WriteLine($"Current Page: {result.PageInfo.Page}");
Console.WriteLine($"Items Per Page: {result.PageInfo.Limit}");
Console.WriteLine($"Total Items: {result.PageInfo.Total}");
Console.WriteLine($"Total Pages: {result.PageInfo.TotalPage}");
```## Extension Methods
The library provides several extension methods through `ToPageDataExtensions`:
- `ToPageData(this List, int page, int limit)`
- `ToPageData(this List, int page, int limit, int total)`
- `ToPageData(this IQueryable, int page, int limit)`
- `ToPageData(this IQueryable, int page, int limit, int total)`
- `ToPageData(this IEnumerable, int page, int limit)`
- `ToPageData(this IEnumerable, int page, int limit, int total)`## License
This project is licensed under the terms specified in the LICENSE file.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## Author
- ozakboy
## Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.