Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

50

Current Page

124 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 124 Results Showing 6151 - 6200 of 24441

ID Name Category Price Stock Rating Reviews SKU
6710 Bulk Product 70e761b9 Electronics $1,005.37 351 3.4 99 BULK-ae4df151
6711 Bulk Product f763506d Clothing $569.04 194 3.5 75 BULK-3672d1bd
6712 Bulk Product fb09613a Sports & Outdoors $193.00 488 1.9 82 BULK-0202cbab
6713 Bulk Product 4b9004f5 Sports & Outdoors $156.69 322 1.6 85 BULK-287fa687
6714 Bulk Product 96c51e0a Books $77.92 105 4.7 65 BULK-c3f7d7e2
6715 Bulk Product fa9df2c0 Clothing $297.74 351 4.9 76 BULK-e4ff2a7c
6716 Bulk Product 1c9ede80 Home & Garden $279.65 155 2.5 31 BULK-3ac2cc58
6717 Bulk Product 5363f65c Electronics $471.07 224 3.4 68 BULK-2a8a13c9
6718 Bulk Product 9eb139cb Electronics $962.94 116 1.4 88 BULK-9e4220f7
6719 Bulk Product 7c18195c Home & Garden $128.50 70 3.3 93 BULK-73d6ffd7
6720 Bulk Product db8275ae Books $629.23 258 3.6 45 BULK-81925b97
6721 Bulk Product 879e2477 Home & Garden $959.26 258 3.4 89 BULK-170c1721
6722 Bulk Product 72e93f1b Clothing $120.87 291 4.0 28 BULK-2aaa536c
6723 Bulk Product ca49c797 Electronics $670.30 375 4.4 95 BULK-ddcaa3bf
6724 Bulk Product ee1eed53 Toys & Games $726.37 246 4.0 5 BULK-5b03220d
6725 Bulk Product 97699d55 Toys & Games $421.86 235 3.6 84 BULK-820b85fc
6726 Bulk Product 5fc1a195 Sports & Outdoors $886.71 73 1.6 93 BULK-319ce72f
6727 Bulk Product 307a218e Home & Garden $852.18 243 1.0 15 BULK-8b2c5713
6728 Bulk Product fd1a071e Electronics $922.54 71 1.4 35 BULK-4a31f5f7
6729 Bulk Product cf8732f9 Books $276.46 341 4.8 18 BULK-59305764
6730 Bulk Product 4d5537c2 Books $511.29 189 0.8 63 BULK-d6a749eb
6731 Bulk Product 8d47051c Clothing $71.07 437 0.8 13 BULK-906a7266
6732 Bulk Product b233946a Sports & Outdoors $628.54 198 1.6 91 BULK-12f10b0d
6733 Bulk Product dea9b847 Sports & Outdoors $697.08 77 1.0 38 BULK-6f454617
6734 Bulk Product dbdd53f4 Clothing $632.90 191 0.8 4 BULK-ed1257c8
6735 Bulk Product 045f003b Books $1,009.98 261 3.0 54 BULK-17430544
6736 Bulk Product eaba0e81 Clothing $291.80 467 3.9 32 BULK-9c3d0dbc
6737 Bulk Product 9b1b0a24 Books $305.49 340 2.9 91 BULK-7ef3ca6d
6738 Bulk Product 6bd3fd44 Sports & Outdoors $77.37 375 0.8 76 BULK-a2bf0b6e
6739 Bulk Product d34026c8 Toys & Games $489.02 235 0.8 88 BULK-469d632b
6740 Bulk Product 30dac662 Sports & Outdoors $60.11 123 0.2 76 BULK-5a346c09
6741 Bulk Product 87dd2b10 Clothing $125.83 48 3.8 82 BULK-85de9b24
6742 Bulk Product 72cd0692 Books $751.91 476 2.7 32 BULK-deec181c
6743 Bulk Product 1e02564f Home & Garden $485.53 171 0.3 23 BULK-7eb73708
6744 Bulk Product 74b0785c Clothing $774.10 143 3.7 36 BULK-9908d2ef
6745 Bulk Product cf7ffc9d Electronics $455.06 392 3.9 7 BULK-851eed65
6746 Bulk Product 0823c19f Toys & Games $848.05 307 3.4 8 BULK-5bd87236
6747 Bulk Product d97d2e88 Home & Garden $276.35 338 3.3 11 BULK-3d32a159
6748 Bulk Product 9f9d7111 Toys & Games $362.80 13 4.9 17 BULK-62bd9be0
6749 Bulk Product 04e7568e Sports & Outdoors $384.18 408 1.6 90 BULK-d0e1f5f3
6750 Bulk Product 2ba26028 Toys & Games $256.09 330 3.9 64 BULK-9967cad9
6751 Bulk Product c54bee7f Toys & Games $667.09 260 2.8 55 BULK-7a11631a
6752 Bulk Product 02f6512d Clothing $48.30 352 3.2 58 BULK-4c08866e
6753 Bulk Product 1493a00d Clothing $148.41 294 0.7 27 BULK-cbcf16aa
6754 Bulk Product 44f94879 Clothing $431.35 297 2.2 12 BULK-3bb9a74e
6755 Bulk Product 2343780e Clothing $817.66 445 1.7 27 BULK-090cb6c6
6756 Bulk Product 025db36c Electronics $674.98 435 2.8 55 BULK-0cabb0e7
6757 Bulk Product 097b06cc Clothing $658.20 435 4.2 89 BULK-a1a17df5
6758 Bulk Product 8e87b25a Home & Garden $520.60 195 2.5 29 BULK-35ca81c7
6759 Bulk Product f9db2f15 Sports & Outdoors $646.95 144 3.2 42 BULK-b95f2b92
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