Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

42 ms

Page Size

50

Current Page

456 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 456 Results Showing 22751 - 22800 of 24441

ID Name Category Price Stock Rating Reviews SKU
23310 Bulk Product 8a48c751 Electronics $478.05 259 4.3 38 BULK-e4f08405
23311 Bulk Product c65da7fd Sports & Outdoors $537.11 496 1.8 79 BULK-f63d7cd5
23312 Bulk Product 20631a9b Sports & Outdoors $391.75 145 2.5 89 BULK-b7bf0cbd
23313 Bulk Product 1da280f5 Home & Garden $345.88 81 0.6 84 BULK-65833f25
23314 Bulk Product b832dec6 Home & Garden $644.76 325 3.0 26 BULK-b845ffbe
23315 Bulk Product 93507f51 Clothing $282.60 19 0.2 78 BULK-f47200bb
23316 Bulk Product 9c0d84b3 Clothing $586.71 188 0.1 10 BULK-a69f937e
23317 Bulk Product 8571b341 Electronics $21.84 231 4.7 91 BULK-c7a39c81
23318 Bulk Product add3aeaa Clothing $422.52 420 2.3 86 BULK-8d68252a
23319 Bulk Product 844f49c6 Books $320.22 439 2.0 67 BULK-3ebb305a
23320 Bulk Product 6d3a5a90 Toys & Games $881.93 168 1.7 88 BULK-7a86fef3
23321 Bulk Product 522341ca Clothing $111.31 415 2.6 23 BULK-3754fe76
23322 Bulk Product 092a4eb9 Books $951.36 200 2.9 48 BULK-4c556c51
23323 Bulk Product 81a26a05 Books $384.06 492 0.7 32 BULK-c60b30ee
23324 Bulk Product 59273ca6 Books $379.14 283 3.7 7 BULK-f8102a00
23325 Bulk Product 526e9791 Electronics $45.19 473 4.5 95 BULK-a316cbcf
23326 Bulk Product afd68e6a Clothing $673.29 488 3.5 77 BULK-72c1af03
23327 Bulk Product 2f92afc3 Sports & Outdoors $938.42 474 1.8 64 BULK-b09200e9
23328 Bulk Product c517a597 Sports & Outdoors $93.48 384 4.6 98 BULK-744dd4b5
23329 Bulk Product 97a602ae Clothing $777.14 342 1.4 5 BULK-134825be
23330 Bulk Product 0474ae0b Sports & Outdoors $18.93 281 0.7 60 BULK-8e3bb78c
23331 Bulk Product 773307f5 Home & Garden $468.92 274 1.0 89 BULK-6dfd2b30
23332 Bulk Product c90a4153 Clothing $90.26 117 0.3 81 BULK-7cf34ccf
23333 Bulk Product a9544990 Home & Garden $812.12 49 3.0 29 BULK-1301f9a4
23334 Bulk Product fd47dd5c Books $809.88 418 3.2 11 BULK-9e6db5c2
23335 Bulk Product ccfe2799 Electronics $462.53 98 2.5 88 BULK-e8d28e42
23336 Bulk Product c2263cc5 Home & Garden $723.77 95 0.0 71 BULK-f3df01e0
23337 Bulk Product 8d278846 Electronics $783.69 329 4.3 81 BULK-42495575
23338 Bulk Product 14b44544 Electronics $652.72 327 5.0 82 BULK-92393a59
23339 Bulk Product 74aaded9 Home & Garden $873.05 109 0.9 30 BULK-018642f1
23340 Bulk Product 7e1b15ab Books $175.16 146 1.7 19 BULK-4d3275cd
23341 Bulk Product 250917b5 Clothing $449.41 246 4.9 22 BULK-3a4a51ba
23342 Bulk Product c381fdc5 Toys & Games $906.72 99 4.0 62 BULK-617a6abc
23343 Bulk Product 17f8b1fa Clothing $737.16 394 1.4 86 BULK-48846f95
23344 Bulk Product 8de9e54c Sports & Outdoors $841.93 90 0.9 64 BULK-24cbccb4
23345 Bulk Product 3bbebcda Toys & Games $181.00 57 4.1 31 BULK-b7922fff
23346 Bulk Product 66b07306 Sports & Outdoors $597.33 277 2.8 14 BULK-6bdd92d0
23347 Bulk Product a768de8a Sports & Outdoors $706.38 121 1.2 10 BULK-171df639
23348 Bulk Product 47e0d3c0 Electronics $694.58 92 1.1 76 BULK-971b6015
23349 Bulk Product 069d454c Toys & Games $540.81 227 3.9 14 BULK-84ab76e9
23350 Bulk Product 44e847cc Electronics $17.83 334 0.9 43 BULK-13631919
23351 Bulk Product a87b960e Electronics $714.64 426 4.2 59 BULK-bbde480b
23352 Bulk Product 2e25b2a8 Home & Garden $392.57 253 3.1 70 BULK-03782c3e
23353 Bulk Product 73f3c9d9 Toys & Games $91.87 370 3.5 65 BULK-c7f3c4df
23354 Bulk Product 0e1beba4 Home & Garden $382.42 362 1.4 12 BULK-a8fd3ff1
23355 Bulk Product afcd441c Electronics $471.24 79 3.5 42 BULK-c10607e2
23356 Bulk Product 83ddf114 Sports & Outdoors $943.08 211 4.3 7 BULK-1d97b894
23357 Bulk Product 4e90d07a Sports & Outdoors $839.85 287 2.2 22 BULK-3a9e8b35
23358 Bulk Product 2add3669 Electronics $761.37 351 2.3 50 BULK-8a25f9a3
23359 Bulk Product d610f2cb Books $177.68 6 1.1 58 BULK-8302bd75
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