Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

28 ms

Page Size

25

Current Page

165 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 165 Results Showing 4101 - 4125 of 24441

ID Name Category Price Stock Rating Reviews SKU
4621 Ultra Electronics Product Max Electronics $744.26 428 4.9 613 SKU-004621
4622 Ultra Books Product Classic Books $752.05 129 1.1 3 SKU-004622
4623 Super Books Product Plus Books $599.91 370 4.4 243 SKU-004623
4624 Standard Office Supplies Product 2024 Office Supplies $609.00 319 3.0 430 SKU-004624
4625 Deluxe Food & Grocery Product Plus Food & Grocery $957.04 499 2.9 30 SKU-004625
4626 Professional Home & Garden Product Pro Home & Garden $469.36 480 3.6 487 SKU-004626
4627 Economy Home & Garden Product Plus Home & Garden $495.46 457 4.5 793 SKU-004627
4628 Pro Books Product Classic Books $21.48 382 4.9 997 SKU-004628
4629 Professional Toys & Games Product XL Toys & Games $39.29 138 3.9 757 SKU-004629
4631 Ultra Health & Beauty Product Mini Health & Beauty $847.20 135 4.7 640 SKU-004631
4632 Deluxe Sports & Outdoors Product Max Sports & Outdoors $353.37 355 3.7 535 SKU-004632
4633 Professional Automotive Product Pro Automotive $968.61 459 1.3 23 SKU-004633
4634 Standard Home & Garden Product Pro Home & Garden $521.08 329 4.7 169 SKU-004634
4635 Premium Clothing Product XL Clothing $470.75 155 2.3 640 SKU-004635
4636 Professional Electronics Product Special Edition Electronics $870.03 487 1.9 709 SKU-004636
4637 Premium Books Product Classic Books $825.85 465 3.2 986 SKU-004637
4638 Elite Office Supplies Product 2024 Office Supplies $481.55 56 3.7 282 SKU-004638
4639 Pro Books Product Plus Books $645.84 492 4.9 651 SKU-004639
4640 Elite Electronics Product Lite Electronics $175.72 227 1.1 356 SKU-004640
4641 Standard Health & Beauty Product Plus Health & Beauty $966.27 470 2.8 157 SKU-004641
4642 Professional Office Supplies Product Special Edition Office Supplies $165.23 332 1.4 835 SKU-004642
4643 Deluxe Electronics Product Advanced Electronics $84.22 278 2.6 782 SKU-004643
4644 Economy Health & Beauty Product XL Health & Beauty $968.32 300 3.3 899 SKU-004644
4646 Ultra Clothing Product Mini Clothing $692.59 57 1.4 251 SKU-004646
4647 Deluxe Toys & Games Product XL Toys & Games $16.29 320 1.5 41 SKU-004647
Implementation Code
// Efficient pagination with Skip and Take
public async Task<PaginatedResult<DemoProduct>> GetPaginatedProductsAsync(int page, int pageSize)
{
    // Get total count (cached if possible)
    var totalCount = await _context.DemoProducts.CountAsync(p => p.IsActive);
    
    // Get page of results
    var items = await _context.DemoProducts
        .Where(p => p.IsActive)
        .OrderBy(p => p.Id) // Important: Must have ORDER BY for consistent paging
        .Skip((page - 1) * pageSize) // OFFSET in SQL
        .Take(pageSize) // FETCH NEXT in SQL
        .AsNoTracking() // No tracking needed for read-only
        .ToListAsync();

    return new PaginatedResult<DemoProduct>
    {
        Items = items,
        TotalCount = totalCount,
        Page = page,
        PageSize = pageSize
    };
}
Pagination Best Practices
  • Always use OrderBy: Skip/Take require stable sorting for consistent results
  • Use AsNoTracking(): Pagination queries are typically read-only
  • Consider caching: Cache total count if dataset changes infrequently
  • Limit max page size: Prevent users from requesting too many records at once
  • Use indexed columns: Ensure ORDER BY columns are indexed for performance