Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

31 ms

Page Size

50

Current Page

404 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 404 Results Showing 20151 - 20200 of 24441

ID Name Category Price Stock Rating Reviews SKU
20710 Bulk Product c3bb745a Sports & Outdoors $265.95 51 2.8 82 BULK-7f7f9df9
20711 Bulk Product bf9c88a5 Home & Garden $490.55 395 1.0 74 BULK-2016521b
20712 Bulk Product fb9004b4 Electronics $859.39 170 0.7 55 BULK-60d09dce
20713 Bulk Product 46a87844 Clothing $139.77 116 2.8 14 BULK-b8bf145d
20714 Bulk Product e87b4e7b Electronics $78.94 488 2.7 54 BULK-fdd14ea5
20715 Bulk Product 13e5da68 Electronics $447.11 176 1.6 54 BULK-3bd39269
20716 Bulk Product 3bdc300d Toys & Games $65.36 45 1.1 14 BULK-63eaaa1e
20717 Bulk Product df400d89 Toys & Games $24.58 151 4.5 0 BULK-0f84e028
20718 Bulk Product 5d4b7596 Home & Garden $960.69 105 1.6 49 BULK-0c50680c
20719 Bulk Product 880a0c43 Home & Garden $261.43 287 4.3 18 BULK-9669f131
20720 Bulk Product f8b947b1 Toys & Games $200.62 274 0.5 71 BULK-8de501fd
20721 Bulk Product 3ca3cd56 Clothing $238.87 118 1.1 94 BULK-2c5a1e83
20722 Bulk Product d3dbba6d Toys & Games $331.08 115 4.0 21 BULK-5d01225f
20723 Bulk Product fbd441d0 Electronics $116.49 268 1.3 82 BULK-98bdcd1b
20724 Bulk Product 7269c72c Books $444.98 118 4.0 86 BULK-6ccf4dc2
20725 Bulk Product 75d149f4 Clothing $935.65 312 4.1 26 BULK-6bcc4f6b
20726 Bulk Product 471ff6b5 Toys & Games $185.18 455 2.6 78 BULK-e04f31ee
20727 Bulk Product fbbb70b4 Sports & Outdoors $156.01 318 4.0 43 BULK-a9c512d5
20728 Bulk Product 9c6c14c5 Sports & Outdoors $818.99 133 3.5 65 BULK-7a65ded1
20729 Bulk Product 3cc9b8d7 Electronics $542.76 168 3.9 58 BULK-43563d97
20730 Bulk Product ef903c1a Books $474.49 151 4.8 1 BULK-900a6116
20731 Bulk Product 6db8ae11 Toys & Games $484.15 336 4.4 18 BULK-8de3e3a9
20732 Bulk Product 1347e2a4 Home & Garden $746.92 228 0.9 45 BULK-3602bc9e
20733 Bulk Product e5051425 Home & Garden $638.30 210 1.5 51 BULK-c5b3fbb3
20734 Bulk Product f6ed1956 Toys & Games $730.80 149 0.3 16 BULK-2e0bae1f
20735 Bulk Product 05fe2e1b Toys & Games $240.80 421 0.3 13 BULK-f41c0d4e
20736 Bulk Product 6b2d1d71 Sports & Outdoors $951.29 206 1.8 95 BULK-b34ba945
20737 Bulk Product 11910172 Toys & Games $642.04 284 3.4 92 BULK-fcd127d0
20738 Bulk Product 223a4b45 Toys & Games $40.58 202 4.7 36 BULK-b360c2e7
20739 Bulk Product f12f7832 Books $349.20 359 1.5 96 BULK-dea2be64
20740 Bulk Product 125bd862 Electronics $811.89 387 2.9 25 BULK-e98fcb83
20741 Bulk Product 045bf79b Sports & Outdoors $258.97 212 1.9 78 BULK-8e6385e7
20742 Bulk Product 9fbe1dd5 Sports & Outdoors $212.32 482 4.7 93 BULK-9e7fc798
20743 Bulk Product 6777a40f Electronics $802.88 41 1.6 54 BULK-21ca96bf
20744 Bulk Product 031bbeeb Electronics $718.60 127 0.8 72 BULK-e3d00da1
20745 Bulk Product d4e5b508 Electronics $580.46 467 3.3 92 BULK-0bb08e09
20746 Bulk Product 2849a272 Clothing $247.21 40 0.0 91 BULK-7cbb2734
20747 Bulk Product 903e6a64 Sports & Outdoors $77.47 360 1.5 70 BULK-844b36c9
20748 Bulk Product 79c37550 Electronics $270.20 230 2.4 36 BULK-a9eeac38
20749 Bulk Product a1af5f2e Toys & Games $307.88 489 4.0 58 BULK-64cf2e5b
20750 Bulk Product bf279d33 Books $67.99 460 1.7 13 BULK-099b5297
20751 Bulk Product 22e19909 Electronics $383.26 379 3.2 21 BULK-0fe4979e
20752 Bulk Product 04172c54 Books $637.19 389 4.6 95 BULK-c26d599e
20753 Bulk Product e5e50ac4 Sports & Outdoors $35.64 344 0.6 11 BULK-39adf4bf
20754 Bulk Product 8e181b00 Books $971.00 123 5.0 98 BULK-f1595aac
20755 Bulk Product 34a3db57 Books $687.52 373 1.1 49 BULK-ad091adf
20756 Bulk Product a9f38c2b Electronics $785.48 473 4.3 20 BULK-b7f4ff8d
20757 Bulk Product 37d4de64 Books $128.13 214 1.7 3 BULK-de0b1b5d
20758 Bulk Product 68b0e413 Sports & Outdoors $720.51 485 4.8 6 BULK-a3c2e1ac
20759 Bulk Product d13fed93 Electronics $406.20 149 3.3 30 BULK-0db2675e
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