Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

570 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 570 Results Showing 14226 - 14250 of 24441

ID Name Category Price Stock Rating Reviews SKU
14785 Bulk Product 593004ff Home & Garden $901.29 96 3.8 27 BULK-e85ebd74
14786 Bulk Product 29d01e3a Books $471.58 421 1.0 60 BULK-074d5137
14787 Bulk Product c7cf91d9 Toys & Games $472.27 43 4.1 82 BULK-ad9f1a0b
14788 Bulk Product 3ba18d18 Electronics $863.86 432 3.0 59 BULK-47dcfe3f
14789 Bulk Product 33cdc28c Electronics $639.89 313 4.6 54 BULK-5a06a1ef
14790 Bulk Product 9bcb33ac Toys & Games $813.55 52 4.8 27 BULK-df125c22
14791 Bulk Product 01df5d02 Clothing $336.92 345 0.4 65 BULK-70278f3a
14792 Bulk Product d2f8c30e Clothing $273.44 337 4.8 7 BULK-f6a34bd7
14793 Bulk Product 2520cf1f Home & Garden $740.74 266 3.0 20 BULK-f49c7fbe
14794 Bulk Product d22b3408 Home & Garden $308.04 271 4.9 93 BULK-e7d631b2
14795 Bulk Product d520bb89 Books $323.02 244 3.5 19 BULK-d8cfb938
14796 Bulk Product 59624f57 Electronics $488.48 71 1.2 94 BULK-4605cb5b
14797 Bulk Product 9fcea10d Toys & Games $881.57 106 4.3 38 BULK-caa0a884
14798 Bulk Product 3363711b Books $513.77 429 4.0 76 BULK-ba13badc
14799 Bulk Product c99228ce Electronics $862.64 17 3.1 71 BULK-6abd779a
14800 Bulk Product 8592535a Clothing $250.04 352 3.9 28 BULK-89503b84
14801 Bulk Product ef7c1931 Electronics $978.94 267 0.1 84 BULK-f3c178aa
14802 Bulk Product 0e83d3b9 Books $891.69 200 0.0 67 BULK-e0a34aa8
14803 Bulk Product 48aad41e Home & Garden $106.35 71 4.2 71 BULK-7f6bba28
14804 Bulk Product c59d25b4 Toys & Games $854.04 155 2.7 77 BULK-82ab7446
14805 Bulk Product b9cb7a0f Electronics $583.46 357 0.7 94 BULK-c22aeb2c
14806 Bulk Product 1775ee3f Clothing $58.40 440 2.1 96 BULK-1bfb8720
14807 Bulk Product f407aafc Toys & Games $801.24 170 2.4 13 BULK-56197cd3
14808 Bulk Product 6da86c24 Electronics $98.07 370 4.3 64 BULK-b8763543
14809 Bulk Product cdbb34e1 Clothing $943.47 478 3.2 42 BULK-f4728752
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