PagedResult<T>
Paginated result set with metadata.
Properties
| Property | Type | Description |
|---|---|---|
| Items | IReadOnlyList<T> | Current page items |
| TotalCount | int | Total items across all pages |
| PageNumber | int | Current page (1-based) |
| PageSize | int | Items per page |
| TotalPages | int | Calculated total pages |
| HasNext | bool | Has next page |
| HasPrevious | bool | Has previous page |
Factory Methods
| Method | Description |
|---|---|
| Empty(int page, int size) | Empty result |
| FromAll(IEnumerable<T>) | Single page with all items |
Instance Methods
| Method | Description |
|---|---|
| Map<TNew>(Func<T, TNew>) | Transform items |
| Where(Func<T, bool>) | Filter current page |
Extension Methods
| Method | Description |
|---|---|
| ToPagedResult(int page, int size) | From IEnumerable |
| ToPagedResult(int total, int page, int size) | Pre-paginated data |
Usage
csharp
public async Task<PagedResult<ProductDto>> GetProductsAsync(int page, int size)
{
var query = _context.Products.Where(p => !p.IsDeleted);
var total = await query.CountAsync();
var items = await query
.Skip((page - 1) * size)
.Take(size)
.ToListAsync();
return items.ToPagedResult(total, page, size);
}