Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

59 ms

Page Size

50

Current Page

350 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 350 Results Showing 17451 - 17500 of 24441

ID Name Category Price Stock Rating Reviews SKU
18010 Bulk Product 12c3f46f Electronics $443.77 192 4.0 34 BULK-237cb8e6
18011 Bulk Product 26780e33 Electronics $312.74 100 1.1 52 BULK-30c25200
18012 Bulk Product d6b4702f Books $582.19 238 2.6 70 BULK-1eaf1c3b
18013 Bulk Product 45e74f91 Sports & Outdoors $225.49 333 2.0 15 BULK-e09f6098
18014 Bulk Product 5dfd5ffb Books $663.17 417 1.9 49 BULK-1f851194
18015 Bulk Product fa4b45c2 Sports & Outdoors $922.93 50 1.7 58 BULK-4af9ccb4
18016 Bulk Product 5174e5d2 Home & Garden $364.76 169 2.5 76 BULK-bba12b79
18017 Bulk Product ac9c760c Sports & Outdoors $752.13 252 4.1 21 BULK-cc8e8de6
18018 Bulk Product 7b5b6f78 Electronics $968.84 450 4.1 81 BULK-ef3912f2
18019 Bulk Product e63b0fd1 Electronics $77.42 262 3.5 17 BULK-704f4027
18020 Bulk Product fd2ea4bf Clothing $998.95 10 2.6 77 BULK-936fc445
18021 Bulk Product 56f01994 Toys & Games $608.81 396 4.3 1 BULK-4dd9ef6e
18022 Bulk Product 3e0bbfbe Electronics $10.43 457 3.7 71 BULK-ded4b0a4
18023 Bulk Product 9a9276cf Books $186.79 29 1.2 60 BULK-389ba372
18024 Bulk Product 0828f932 Clothing $258.96 314 2.3 67 BULK-d262245a
18025 Bulk Product 12ecf354 Clothing $557.28 168 4.5 7 BULK-feb8bd65
18026 Bulk Product c7909a67 Toys & Games $887.10 229 4.2 13 BULK-a068796e
18027 Bulk Product 4c564976 Books $989.29 388 1.9 62 BULK-b15924ad
18028 Bulk Product 897931f5 Sports & Outdoors $948.89 41 0.9 98 BULK-32f1ff56
18029 Bulk Product 31dab05f Electronics $517.91 148 3.7 20 BULK-fb14296f
18030 Bulk Product cfef0fb3 Sports & Outdoors $622.56 56 1.0 6 BULK-e14e59c6
18031 Bulk Product cee31ae1 Electronics $374.95 254 2.2 87 BULK-36a7c152
18032 Bulk Product 8e861659 Home & Garden $899.04 431 2.2 82 BULK-47d6f750
18033 Bulk Product 0d94d758 Sports & Outdoors $761.58 164 3.0 84 BULK-a8dcd510
18034 Bulk Product dc1b80f2 Books $267.06 264 4.5 75 BULK-3a6343a3
18035 Bulk Product 74cff3df Books $346.63 278 3.8 95 BULK-77ee89a9
18036 Bulk Product b3149060 Electronics $140.83 13 0.6 79 BULK-eb4d834e
18037 Bulk Product a4e1fb4c Home & Garden $868.45 79 0.9 32 BULK-18eb0a26
18038 Bulk Product a2cce560 Clothing $762.01 57 2.4 26 BULK-7b7a5319
18039 Bulk Product 2c7e59ce Books $646.85 474 2.9 11 BULK-dd59e0af
18040 Bulk Product 88214149 Home & Garden $59.32 47 2.1 56 BULK-c767a231
18041 Bulk Product 4276a30b Sports & Outdoors $739.26 5 3.7 81 BULK-7503479e
18042 Bulk Product 2896e56f Sports & Outdoors $923.19 355 3.6 5 BULK-f231d212
18043 Bulk Product 50e029c6 Books $379.69 40 3.6 69 BULK-8274cd71
18044 Bulk Product 56388660 Electronics $669.40 289 4.5 13 BULK-3365a84d
18045 Bulk Product e12eff3f Clothing $688.92 407 1.1 92 BULK-82603c96
18046 Bulk Product af88334d Electronics $922.17 271 1.6 22 BULK-ccfc15f6
18047 Bulk Product 8ac4489b Books $312.89 40 0.4 23 BULK-512a0305
18048 Bulk Product 4f272c64 Electronics $486.73 39 2.3 37 BULK-bc67c20f
18049 Bulk Product 95632c08 Books $369.96 114 0.2 97 BULK-b2839057
18050 Bulk Product cd806e6d Toys & Games $587.71 389 1.5 68 BULK-e952cc86
18051 Bulk Product eee37a82 Sports & Outdoors $938.43 252 4.5 59 BULK-36a50d46
18052 Bulk Product c9b10299 Toys & Games $674.15 237 0.0 91 BULK-5f3b1e48
18053 Bulk Product 379d2df3 Sports & Outdoors $500.59 247 2.9 40 BULK-77ed05fb
18054 Bulk Product 4da4afdf Sports & Outdoors $371.09 454 1.3 98 BULK-95a5ecbd
18055 Bulk Product a3e0ffd2 Clothing $984.88 294 4.1 0 BULK-1b01f232
18056 Bulk Product 872b9819 Books $559.05 412 2.6 84 BULK-d57657ca
18057 Bulk Product 9429e61b Clothing $981.16 340 3.1 54 BULK-4e13bc86
18058 Bulk Product eb5b8c7d Sports & Outdoors $416.32 281 4.9 50 BULK-b5429734
18059 Bulk Product 34752ab8 Electronics $527.30 369 3.3 89 BULK-0e0fdb18
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