Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

435 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 435 Results Showing 10851 - 10875 of 24441

ID Name Category Price Stock Rating Reviews SKU
11410 Bulk Product 47a644a6 Electronics $449.50 89 4.1 85 BULK-ea8abf0e
11411 Bulk Product 3d23dcbf Home & Garden $418.22 16 2.5 37 BULK-5e33bedd
11412 Bulk Product 383b818a Toys & Games $602.23 28 0.9 76 BULK-de63d889
11413 Bulk Product 5cee38d9 Clothing $219.41 312 3.6 61 BULK-34f94c30
11414 Bulk Product 4087b5c0 Home & Garden $500.45 301 2.3 59 BULK-26152819
11415 Bulk Product 248fe211 Clothing $228.32 383 4.2 61 BULK-3ee4cc7d
11416 Bulk Product 6f99b831 Electronics $905.18 127 3.7 49 BULK-24bc0c32
11417 Bulk Product 56bcfe12 Electronics $160.27 349 3.0 15 BULK-562335dc
11418 Bulk Product d064c39a Sports & Outdoors $201.54 199 4.2 10 BULK-9e1b428d
11419 Bulk Product 03822b96 Books $828.24 146 2.1 35 BULK-36f0634b
11420 Bulk Product ed9b6095 Books $239.52 471 2.9 55 BULK-dff1a8c9
11421 Bulk Product 5d7be598 Electronics $170.66 95 3.3 71 BULK-d524df5f
11422 Bulk Product 5adca417 Home & Garden $121.24 367 2.0 42 BULK-1b478a8b
11423 Bulk Product 3b9f2673 Books $735.51 243 4.8 83 BULK-b8cdeb25
11424 Bulk Product ff3329eb Clothing $567.09 451 4.3 48 BULK-8fb4be93
11425 Bulk Product 327fa172 Toys & Games $515.19 149 2.4 46 BULK-e1c56e37
11426 Bulk Product 7dc8423a Clothing $467.58 495 3.8 37 BULK-6c02ae73
11427 Bulk Product e4fddefd Toys & Games $362.80 428 1.3 76 BULK-3c54984f
11428 Bulk Product 7cec22aa Books $791.11 362 1.1 12 BULK-5c8ec37e
11429 Bulk Product 820a1dd5 Home & Garden $201.25 460 4.9 43 BULK-3d8a3858
11430 Bulk Product bf2d45e0 Electronics $984.64 377 1.2 91 BULK-0ca47a73
11431 Bulk Product 3a5b8d0f Books $559.21 462 4.7 66 BULK-af654970
11432 Bulk Product a4b6b329 Sports & Outdoors $392.20 23 3.0 35 BULK-429d410a
11433 Bulk Product 73b30064 Home & Garden $966.40 6 1.7 59 BULK-621336ae
11434 Bulk Product 34b6a17f Home & Garden $972.16 346 2.0 63 BULK-dc86caa7
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