Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

50

Current Page

330 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 330 Results Showing 16451 - 16500 of 24441

ID Name Category Price Stock Rating Reviews SKU
17010 Bulk Product 26689b74 Books $473.06 290 4.4 21 BULK-140a3736
17011 Bulk Product 88bc2569 Clothing $174.59 478 3.3 11 BULK-41487664
17012 Bulk Product 606139a6 Books $281.28 186 0.6 6 BULK-eef70fbd
17013 Bulk Product 678153e7 Sports & Outdoors $758.16 424 2.7 40 BULK-821078b2
17014 Bulk Product e559a6e1 Books $224.56 305 0.9 68 BULK-cefd81ee
17015 Bulk Product d508c664 Sports & Outdoors $658.62 349 0.7 9 BULK-ec460aae
17016 Bulk Product f4639443 Clothing $514.58 359 2.6 76 BULK-bc6b4e64
17017 Bulk Product 9d7db265 Home & Garden $353.14 63 3.1 60 BULK-ef14c907
17018 Bulk Product ea11b2ee Books $994.36 364 2.2 12 BULK-d5375436
17019 Bulk Product 5401dbe2 Home & Garden $492.33 221 0.4 2 BULK-36918899
17020 Bulk Product 309f921d Clothing $505.19 346 3.2 11 BULK-37716e83
17021 Bulk Product bfc9e171 Home & Garden $214.08 195 2.4 15 BULK-3f76a668
17022 Bulk Product 54ae873e Clothing $454.30 346 3.8 72 BULK-735015c1
17023 Bulk Product d8675ad2 Home & Garden $732.68 86 3.0 89 BULK-d51a5453
17024 Bulk Product 81b396ec Toys & Games $912.44 424 1.7 93 BULK-fcd66a47
17025 Bulk Product d960ee17 Electronics $801.85 442 0.8 76 BULK-93270ff7
17026 Bulk Product e54b0bad Electronics $322.27 347 1.2 46 BULK-b4215e6b
17027 Bulk Product c65da8d1 Sports & Outdoors $856.13 189 3.2 79 BULK-524f0c24
17028 Bulk Product 63fd8792 Sports & Outdoors $147.01 134 3.6 66 BULK-b2e92b04
17029 Bulk Product 000558e6 Toys & Games $294.87 20 4.3 10 BULK-76693fe8
17030 Bulk Product 3da3d756 Home & Garden $92.29 223 4.3 12 BULK-76ae6a5b
17031 Bulk Product 6b555d0c Books $129.06 432 4.5 18 BULK-e29da7e5
17032 Bulk Product 5f128817 Books $977.16 222 3.4 98 BULK-27367a2c
17033 Bulk Product 0ecfa942 Home & Garden $371.04 285 0.9 4 BULK-ea3b4485
17034 Bulk Product c0aaad1f Electronics $23.22 442 3.7 69 BULK-3f49dbf6
17035 Bulk Product 51352dce Home & Garden $931.18 145 4.8 15 BULK-cc5f6e4c
17036 Bulk Product 41bb0033 Electronics $153.29 281 4.0 24 BULK-1eae25dd
17037 Bulk Product 7d3eb6c5 Electronics $97.07 200 0.7 99 BULK-dbe39558
17038 Bulk Product 5c76339d Home & Garden $888.08 412 2.3 82 BULK-60d52633
17039 Bulk Product 7229f5fa Electronics $94.31 499 3.0 43 BULK-c4e64b59
17040 Bulk Product 06871ff8 Sports & Outdoors $246.32 425 0.6 84 BULK-90da6a98
17041 Bulk Product 5ae0ec78 Clothing $805.09 0 3.6 71 BULK-9a3ce5b7
17042 Bulk Product 1fc85536 Books $800.52 360 3.3 61 BULK-aa30f1b5
17043 Bulk Product ef5cc9f6 Electronics $355.73 159 0.4 74 BULK-fea82082
17044 Bulk Product f3a0ad06 Sports & Outdoors $707.78 344 3.0 8 BULK-5e8ffbb7
17045 Bulk Product 47f25e78 Clothing $394.24 491 1.4 44 BULK-1d43e64e
17046 Bulk Product be056218 Electronics $157.75 210 1.8 47 BULK-b85626b9
17047 Bulk Product 082b490b Toys & Games $324.21 323 2.1 18 BULK-65fe5710
17048 Bulk Product e647c6e1 Home & Garden $434.52 475 2.1 48 BULK-0169a745
17049 Bulk Product bbd7d97b Sports & Outdoors $629.61 311 2.6 49 BULK-a45ef521
17050 Bulk Product f04527d4 Toys & Games $274.91 377 0.8 55 BULK-0ff12ee2
17051 Bulk Product dfa48f06 Sports & Outdoors $906.20 311 0.8 90 BULK-048b18f2
17052 Bulk Product 0f508afc Clothing $954.80 490 4.6 37 BULK-b0aeef15
17053 Bulk Product f2e54c5e Books $219.97 291 2.4 82 BULK-31a3696a
17054 Bulk Product 62fc9891 Toys & Games $483.18 23 4.4 16 BULK-df344bc6
17055 Bulk Product 8d2be23a Electronics $61.46 83 2.9 24 BULK-e44e43db
17056 Bulk Product 21bc1daa Toys & Games $844.96 382 3.3 80 BULK-88c0b73a
17057 Bulk Product 00131a6e Clothing $385.86 429 1.6 5 BULK-17bcc99f
17058 Bulk Product bfa7a7a9 Clothing $344.54 202 0.1 35 BULK-d1cb5185
17059 Bulk Product dc559679 Home & Garden $88.75 418 3.1 78 BULK-ddc9ed1f
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