Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

915 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 915 Results Showing 22851 - 22875 of 24441

ID Name Category Price Stock Rating Reviews SKU
23410 Bulk Product c236eab7 Home & Garden $977.63 183 3.9 73 BULK-0b261324
23411 Bulk Product 84446e94 Toys & Games $326.83 262 0.9 91 BULK-52ea16c0
23412 Bulk Product 5c8db6fa Home & Garden $339.90 20 4.6 89 BULK-63348af0
23413 Bulk Product 379b45b1 Books $979.92 332 0.3 25 BULK-b36b1ac0
23414 Bulk Product 3795fd45 Sports & Outdoors $141.30 38 2.8 17 BULK-17ad8d7d
23415 Bulk Product b9482776 Clothing $682.68 344 3.3 52 BULK-a8e7e665
23416 Bulk Product 9ae2c664 Toys & Games $1,000.78 82 0.1 32 BULK-a38d4a57
23417 Bulk Product 0d3210b9 Sports & Outdoors $429.15 97 4.3 76 BULK-c081ff8f
23418 Bulk Product 80be542d Clothing $72.81 104 1.3 58 BULK-f478a9fb
23419 Bulk Product 8fb49ea6 Sports & Outdoors $888.79 362 2.6 34 BULK-15b593d3
23420 Bulk Product 55da3e38 Electronics $723.74 24 0.2 15 BULK-41553793
23421 Bulk Product 5b7de046 Sports & Outdoors $36.62 8 0.2 30 BULK-c717416f
23422 Bulk Product 62816dc9 Toys & Games $110.23 346 1.3 27 BULK-b8941ed0
23423 Bulk Product c7760e69 Clothing $559.34 167 4.9 98 BULK-bcebe533
23424 Bulk Product 1faff3bd Books $101.15 483 0.6 86 BULK-f05a9cc5
23425 Bulk Product 3df37ce1 Electronics $218.27 142 1.1 19 BULK-70a2c49e
23426 Bulk Product b5ab4dcb Books $271.29 35 1.1 18 BULK-5a32be4f
23427 Bulk Product b3744774 Clothing $160.98 486 4.3 87 BULK-6525e89f
23428 Bulk Product d7ec6dbf Home & Garden $943.90 479 3.2 70 BULK-e3159f1d
23429 Bulk Product 8d8b39dc Electronics $749.48 424 3.5 97 BULK-6d548dd4
23430 Bulk Product f9cc85e2 Books $729.36 474 4.3 24 BULK-6ffb72f3
23431 Bulk Product a74222c0 Home & Garden $184.73 353 4.9 28 BULK-9615051c
23432 Bulk Product b32619ea Books $285.65 489 4.5 88 BULK-1acf7fac
23433 Bulk Product 1e730d63 Home & Garden $775.10 25 4.5 30 BULK-0d17d7c0
23434 Bulk Product 70326b85 Toys & Games $775.30 69 2.9 88 BULK-8fc9520a
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