Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

968 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 968 Results Showing 24176 - 24200 of 24441

ID Name Category Price Stock Rating Reviews SKU
24735 Bulk Product 203dc235 Clothing $374.26 146 2.3 58 BULK-c1c195cd
24736 Bulk Product bc7d8b6a Toys & Games $944.80 342 3.1 70 BULK-bdf74c42
24737 Bulk Product e395d55d Clothing $595.41 302 4.8 61 BULK-be95f52e
24738 Bulk Product 9355874e Home & Garden $579.37 105 3.5 24 BULK-d1e915e8
24739 Bulk Product 8141c7c6 Home & Garden $552.07 446 3.8 52 BULK-2220540f
24740 Bulk Product ef70eb34 Electronics $775.07 91 4.8 42 BULK-c6e43a39
24741 Bulk Product 445e8f5a Home & Garden $819.48 327 0.6 34 BULK-85f83ba9
24742 Bulk Product a925a252 Toys & Games $908.09 465 1.3 3 BULK-1c6324ad
24743 Bulk Product 5cbf473c Sports & Outdoors $179.64 451 1.2 73 BULK-d12eecab
24744 Bulk Product 37a267ce Sports & Outdoors $141.59 261 0.3 3 BULK-5b0dcf0a
24745 Bulk Product ae98e9b9 Clothing $282.24 382 0.2 69 BULK-b839e829
24746 Bulk Product b1197397 Clothing $570.80 77 1.0 77 BULK-6bd28313
24747 Bulk Product 7e84fbc6 Books $141.93 19 2.8 78 BULK-26fc14ad
24748 Bulk Product 4f5ff46d Toys & Games $46.95 252 3.2 21 BULK-d586695c
24749 Bulk Product 8173a4a5 Books $28.12 453 1.7 52 BULK-bb5f23b8
24750 Bulk Product 8e4ffc4b Toys & Games $457.44 260 4.1 25 BULK-0998e9e1
24751 Bulk Product f2e43b29 Books $359.56 171 3.7 27 BULK-564843e4
24752 Bulk Product ce2314a1 Sports & Outdoors $213.02 221 4.5 47 BULK-3a295be2
24753 Bulk Product cdfadf8f Electronics $960.70 24 1.7 66 BULK-bf1acd7a
24754 Bulk Product 1210ffbe Sports & Outdoors $961.79 55 1.5 75 BULK-6d15a27b
24755 Bulk Product 3cbb3509 Toys & Games $557.38 459 3.8 61 BULK-ff57f265
24756 Bulk Product 8c61f6dc Electronics $43.56 89 2.2 5 BULK-2f90c60e
24757 Bulk Product d7f98966 Books $79.93 5 2.3 70 BULK-edd416f9
24758 Bulk Product 6ed4862a Electronics $412.14 155 1.0 97 BULK-72a7f43e
24759 Bulk Product 1b99f168 Electronics $320.50 268 1.1 54 BULK-9a3c00cd
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