Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

93 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 93 Results Showing 2301 - 2325 of 24441

ID Name Category Price Stock Rating Reviews SKU
2585 Ultra Toys & Games Product XL Toys & Games $578.76 468 4.0 810 SKU-002585
2586 Pro Clothing Product Special Edition Clothing $544.13 24 1.5 79 SKU-002586
2587 Elite Clothing Product Classic Clothing $831.69 410 1.5 896 SKU-002587
2588 Mega Clothing Product Advanced Clothing $801.36 268 2.8 166 SKU-002588
2589 Economy Health & Beauty Product Pro Health & Beauty $309.64 126 1.9 216 SKU-002589
2592 Standard Sports & Outdoors Product Pro Sports & Outdoors $877.62 333 4.9 822 SKU-002592
2593 Elite Toys & Games Product Max Toys & Games $266.35 220 3.7 538 SKU-002593
2594 Deluxe Home & Garden Product Mini Home & Garden $164.46 46 1.1 153 SKU-002594
2595 Professional Food & Grocery Product Plus Food & Grocery $580.48 10 3.5 264 SKU-002595
2596 Super Health & Beauty Product Classic Health & Beauty $856.48 79 2.3 4 SKU-002596
2597 Pro Clothing Product Special Edition Clothing $427.95 450 3.7 238 SKU-002597
2598 Elite Sports & Outdoors Product Mini Sports & Outdoors $752.43 37 1.5 123 SKU-002598
2599 Ultra Clothing Product 2024 Clothing $559.37 480 2.3 855 SKU-002599
2601 Professional Office Supplies Product Plus Office Supplies $824.29 74 2.3 886 SKU-002601
2602 Super Sports & Outdoors Product XL Sports & Outdoors $693.72 369 3.7 55 SKU-002602
2603 Professional Electronics Product Advanced Electronics $112.71 497 1.6 504 SKU-002603
2604 Standard Electronics Product Classic Electronics $910.26 201 2.7 505 SKU-002604
2606 Elite Books Product Advanced Books $150.25 180 3.8 349 SKU-002606
2607 Pro Automotive Product Pro Automotive $204.06 87 2.6 834 SKU-002607
2609 Ultra Sports & Outdoors Product Classic Sports & Outdoors $308.62 191 2.2 368 SKU-002609
2610 Super Books Product Max Books $623.93 153 4.6 86 SKU-002610
2611 Premium Books Product Classic Books $867.78 151 3.6 779 SKU-002611
2613 Professional Automotive Product Pro Automotive $662.25 488 4.1 760 SKU-002613
2614 Pro Clothing Product Classic Clothing $414.19 309 2.9 303 SKU-002614
2615 Economy Sports & Outdoors Product Max Sports & Outdoors $979.41 78 4.8 718 SKU-002615
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