Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

36 ms

Page Size

25

Current Page

244 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 244 Results Showing 6076 - 6100 of 24441

ID Name Category Price Stock Rating Reviews SKU
6635 Bulk Product 9b1e5756 Electronics $445.19 189 1.2 34 BULK-9438575c
6636 Bulk Product 8f53a28d Clothing $599.32 210 2.9 94 BULK-ae8156ef
6637 Bulk Product 2937c3eb Toys & Games $927.35 355 3.5 71 BULK-782154b5
6638 Bulk Product ffc3bb18 Clothing $61.56 414 1.6 44 BULK-ba9d512c
6639 Bulk Product ddd265a2 Electronics $763.09 449 0.5 60 BULK-45fc07a0
6640 Bulk Product 545c0441 Books $172.54 192 3.6 14 BULK-b729895c
6641 Bulk Product b948c4e8 Books $566.61 93 2.1 89 BULK-3165a302
6642 Bulk Product fdf01219 Electronics $229.75 35 3.7 54 BULK-60841828
6643 Bulk Product dc2481ff Electronics $396.32 208 4.6 67 BULK-71e0bc0e
6644 Bulk Product dca8a2a4 Sports & Outdoors $703.15 163 4.6 50 BULK-c83014ad
6645 Bulk Product 4b5d1de5 Home & Garden $499.62 151 1.6 76 BULK-f3a2c5be
6646 Bulk Product eef0dba6 Home & Garden $184.20 430 3.6 26 BULK-3476a791
6647 Bulk Product a746afed Sports & Outdoors $249.07 14 1.4 90 BULK-92398321
6648 Bulk Product bfa920a9 Books $983.46 431 1.7 25 BULK-0396f005
6649 Bulk Product 4645d577 Books $273.51 247 0.0 76 BULK-ab5429d1
6650 Bulk Product 4cf58908 Electronics $884.89 51 0.4 19 BULK-fbbdafb8
6651 Bulk Product 8717189a Electronics $51.65 108 0.5 40 BULK-aab5dd20
6652 Bulk Product 469ab286 Sports & Outdoors $364.05 398 2.7 56 BULK-70f0d5d2
6653 Bulk Product 9597d22a Toys & Games $985.99 110 1.7 43 BULK-b9cee044
6654 Bulk Product 98477a4c Toys & Games $765.23 401 1.3 81 BULK-9982e035
6655 Bulk Product 82257925 Toys & Games $444.17 105 3.2 42 BULK-7a62dd6b
6656 Bulk Product 10cbd06f Electronics $223.76 249 1.7 6 BULK-521eadc4
6657 Bulk Product 360f2a37 Sports & Outdoors $444.05 211 0.0 38 BULK-6832f4dd
6658 Bulk Product cbaca959 Home & Garden $591.95 474 1.6 48 BULK-80f2966c
6659 Bulk Product 8345577a Toys & Games $276.37 460 4.7 66 BULK-f074d531
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