Overview
TheIntent.Application.Dtos.Pagination module provides pagination infrastructure for your application services. It generates PagedResult<T> and CursorPagedResult<T> types along with mapping extensions for seamless integration with repositories and domain queries.
Module:
Intent.Application.Dtos.PaginationVersion: 4.1.5+Dependencies:Intent.Application.DtosIntent.Modelers.ServicesIntent.Modelers.Domain
Key Features
- Offset Pagination: Traditional page number/page size pagination
- Cursor Pagination: Efficient cursor-based pagination for large datasets
- Mapping Extensions: Convert repository results to paginated DTOs
- Configurable Defaults: Set default page sizes and ordering
- Type Safety: Generic result types for any DTO
- Integration: Works with EF Core, CosmosDB, MongoDB, Redis OM, and more
Installation
Pagination Types
PagedResult<T>
Traditional offset-based pagination using page numbers:PagedResult.cs
- UI pagination with page numbers
- Small to medium datasets
- When users need to jump to specific pages
- RESTful APIs with page-based navigation
CursorPagedResult<T>
Cursor-based pagination for efficient traversal:CursorPagedResult.cs
- Infinite scrolling UIs
- Large datasets
- Real-time data feeds
- GraphQL APIs
- When page jumping is not required
Configuration
Module Settings
Access pagination settings in application settings:Page Size Default
Type:number
Default: 20
Sets the default page size for all paginated services.
Order By Default
Type:text
Default: "" (empty)
Defines the default ordering expression for paginated queries (e.g., "Name", "CreatedDate desc").
Usage in Services
Defining Paginated Operations
In the Services Designer, you can mark operations to return paginated results:Generated Service Contract
IProductService.cs
Implementation Example
ProductService.cs
Mapping Extensions
The module generates extension methods for converting between paginated types:PagedResult Mapping Extensions
Generated Extensions
CursorPagedResult Mapping Extensions
Cursor Extensions
Advanced Usage
Filtering and Sorting
Combine pagination with filtering and sorting:Advanced Query
Cursor-Based Pagination
For cursor-based pagination with repositories:Cursor Pagination
Empty Results
Handle empty result sets gracefully:Empty Result
Integration with Repositories
The pagination module automatically integrates with repository interfaces:Entity Framework Core
EF Core Repository
CosmosDB
CosmosDB Repository
MongoDB
MongoDB Repository
Best Practices
Choose the Right Pagination Type
Choose the Right Pagination Type
- Use offset pagination (
PagedResult) for UI grids, admin panels, and reports - Use cursor pagination (
CursorPagedResult) for feeds, activity streams, and mobile apps - Consider your data size: cursor pagination scales better for millions of records
Set Reasonable Page Sizes
Set Reasonable Page Sizes
- Default to 20-50 items per page for most use cases
- Limit maximum page size to prevent performance issues (e.g., 100)
- Adjust based on payload size (smaller items = larger page size)
Use Projections for Performance
Use Projections for Performance
Always project to DTOs at the database level using AutoMapper’s
ProjectTo:Include Total Count Metadata
Include Total Count Metadata
Always return
TotalCount and PageCount so clients can:- Display “Showing 1-20 of 157 results”
- Render page numbers accurately
- Disable next/previous buttons appropriately
Frontend Integration
REST API Response
Example Response
React Example
React Component
Troubleshooting
Pagination Not Applied
Pagination Not Applied
Issue: Service operation doesn’t return paginated results.Solution:
- Verify the Paginated stereotype is applied in the designer
- Run the Software Factory to regenerate contracts
- Check that the repository implements the pagination interface
Mapping Extension Not Found
Mapping Extension Not Found
Issue:
MapToPagedResult method not available.Solution:- Ensure
Intent.Application.Dtos.Paginationis installed - Check the namespace imports include
YourApp.Application.Common.Pagination - Rebuild the solution
Performance Issues
Performance Issues
Issue: Paginated queries are slow.Solution:
- Add database indexes on frequently sorted/filtered columns
- Use
ProjectTofor AutoMapper projections - Limit maximum page size
- Consider cursor pagination for very large datasets
Related Modules
- DTOs - Base DTO generation
- AutoMapper Integration - DTO mapping
- Repository Interfaces - Repository pagination support
- Entity Framework Core - EF Core repository implementation
