Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

526 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 526 Results Showing 13126 - 13150 of 24441

ID Name Category Price Stock Rating Reviews SKU
13685 Bulk Product 3afa5b7b Books $841.58 50 2.2 56 BULK-b767c118
13686 Bulk Product 51a7e7ba Clothing $296.73 20 4.4 51 BULK-60f14db0
13687 Bulk Product e372d8ca Electronics $81.51 157 1.6 13 BULK-67f5cf81
13688 Bulk Product b29661f2 Sports & Outdoors $245.54 314 3.7 76 BULK-bca03a4c
13689 Bulk Product 960f50af Toys & Games $715.35 420 1.0 94 BULK-e3984235
13690 Bulk Product 7e7c1f89 Toys & Games $406.61 127 3.9 35 BULK-e73e9b7d
13691 Bulk Product 88e6d0c0 Clothing $381.06 279 0.1 34 BULK-8a15a858
13692 Bulk Product 41551984 Sports & Outdoors $998.33 294 2.8 42 BULK-67cb577a
13693 Bulk Product d1ab90b4 Electronics $308.45 462 0.2 43 BULK-feedb5cd
13694 Bulk Product 168b1dab Toys & Games $634.51 495 3.8 15 BULK-0c9f08a2
13695 Bulk Product c801c111 Home & Garden $236.47 173 3.3 14 BULK-1df956a7
13696 Bulk Product 26e5c8eb Home & Garden $539.52 77 2.4 38 BULK-dee66df9
13697 Bulk Product 3eeec884 Sports & Outdoors $322.25 169 1.8 55 BULK-2531a1d5
13698 Bulk Product aa32cc69 Sports & Outdoors $70.44 409 2.7 69 BULK-bd8a4c80
13699 Bulk Product 616d10cd Electronics $762.02 315 3.5 12 BULK-91f5e80e
13700 Bulk Product f4bade9d Toys & Games $673.97 162 0.7 68 BULK-bc6bf403
13701 Bulk Product 229654f2 Clothing $481.93 269 4.2 81 BULK-12c99596
13702 Bulk Product 649c68e9 Clothing $327.74 211 2.3 54 BULK-418e39ca
13703 Bulk Product f7de3b62 Home & Garden $34.91 116 3.2 22 BULK-1151e503
13704 Bulk Product 7a36ad47 Books $560.24 131 4.1 30 BULK-a1a90bcb
13705 Bulk Product acd629f5 Toys & Games $127.04 275 2.0 55 BULK-dd652a76
13706 Bulk Product 61bd8660 Toys & Games $131.98 463 2.0 68 BULK-947ba547
13707 Bulk Product 5d880ce9 Sports & Outdoors $654.23 31 1.9 8 BULK-3d60f3c9
13708 Bulk Product 5f0070d9 Electronics $403.87 301 3.8 26 BULK-fcde786e
13709 Bulk Product 41f843b5 Clothing $372.83 170 1.3 25 BULK-403c2c24
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