Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

94 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 94 Results Showing 2326 - 2350 of 24441

ID Name Category Price Stock Rating Reviews SKU
2616 Super Electronics Product Pro Electronics $117.87 384 1.1 414 SKU-002616
2617 Pro Toys & Games Product Pro Toys & Games $222.82 250 2.9 182 SKU-002617
2619 Economy Books Product Advanced Books $671.07 471 3.1 709 SKU-002619
2620 Standard Food & Grocery Product Pro Food & Grocery $285.55 4 3.2 356 SKU-002620
2621 Premium Automotive Product Mini Automotive $55.88 125 3.1 716 SKU-002621
2622 Standard Sports & Outdoors Product Pro Sports & Outdoors $295.56 111 4.3 19 SKU-002622
2623 Deluxe Sports & Outdoors Product Max Sports & Outdoors $850.66 381 2.2 745 SKU-002623
2624 Pro Health & Beauty Product Advanced Health & Beauty $718.83 1 4.7 667 SKU-002624
2625 Premium Electronics Product Advanced Electronics $877.59 339 4.8 410 SKU-002625
2627 Ultra Automotive Product Advanced Automotive $703.40 439 4.6 811 SKU-002627
2628 Economy Automotive Product Pro Automotive $506.45 472 1.8 351 SKU-002628
2629 Elite Toys & Games Product Lite Toys & Games $207.55 399 4.6 201 SKU-002629
2630 Mega Sports & Outdoors Product Classic Sports & Outdoors $187.97 460 4.9 130 SKU-002630
2631 Deluxe Clothing Product Advanced Clothing $185.64 176 4.6 761 SKU-002631
2632 Ultra Clothing Product Classic Clothing $797.13 290 2.5 555 SKU-002632
2633 Elite Health & Beauty Product Advanced Health & Beauty $243.38 345 4.9 270 SKU-002633
2634 Ultra Office Supplies Product XL Office Supplies $894.19 229 3.7 744 SKU-002634
2635 Deluxe Food & Grocery Product Pro Food & Grocery $818.24 286 4.7 213 SKU-002635
2636 Standard Electronics Product Advanced Electronics $801.45 91 4.7 554 SKU-002636
2637 Pro Home & Garden Product Advanced Home & Garden $434.23 429 4.5 688 SKU-002637
2638 Mega Clothing Product Advanced Clothing $372.13 71 4.3 3 SKU-002638
2639 Ultra Sports & Outdoors Product Special Edition Sports & Outdoors $442.73 382 2.1 965 SKU-002639
2640 Ultra Clothing Product Classic Clothing $954.55 177 4.0 415 SKU-002640
2641 Professional Clothing Product Lite Clothing $718.28 201 1.6 711 SKU-002641
2642 Mega Sports & Outdoors Product 2024 Sports & Outdoors $87.13 450 4.3 757 SKU-002642
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