Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

76 ms

Page Size

25

Current Page

97 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 97 Results Showing 2401 - 2425 of 24441

ID Name Category Price Stock Rating Reviews SKU
2697 Deluxe Clothing Product Lite Clothing $909.31 149 4.2 265 SKU-002697
2698 Mega Automotive Product XL Automotive $935.79 328 3.6 427 SKU-002698
2699 Mega Books Product Mini Books $182.35 211 3.9 959 SKU-002699
2700 Economy Automotive Product 2024 Automotive $738.89 395 4.2 734 SKU-002700
2701 Premium Sports & Outdoors Product Lite Sports & Outdoors $670.46 437 3.2 830 SKU-002701
2702 Pro Clothing Product Special Edition Clothing $164.24 452 2.2 588 SKU-002702
2703 Economy Electronics Product Max Electronics $111.19 274 4.7 75 SKU-002703
2704 Deluxe Office Supplies Product Lite Office Supplies $927.24 411 2.5 110 SKU-002704
2705 Premium Clothing Product Pro Clothing $443.71 198 4.2 319 SKU-002705
2707 Premium Clothing Product Pro Clothing $419.38 189 1.5 477 SKU-002707
2708 Elite Home & Garden Product Advanced Home & Garden $332.37 90 3.3 919 SKU-002708
2709 Economy Sports & Outdoors Product Mini Sports & Outdoors $453.52 418 4.9 189 SKU-002709
2710 Professional Books Product Classic Books $13.36 311 2.7 267 SKU-002710
2711 Super Toys & Games Product Max Toys & Games $536.21 497 2.8 594 SKU-002711
2712 Premium Electronics Product Classic Electronics $762.49 417 1.4 111 SKU-002712
2713 Standard Office Supplies Product Plus Office Supplies $509.81 446 2.6 857 SKU-002713
2714 Professional Office Supplies Product Pro Office Supplies $667.54 55 1.2 140 SKU-002714
2715 Ultra Electronics Product Max Electronics $857.96 431 1.4 97 SKU-002715
2716 Ultra Sports & Outdoors Product Lite Sports & Outdoors $243.69 126 1.2 154 SKU-002716
2717 Premium Automotive Product Plus Automotive $639.81 455 3.7 322 SKU-002717
2718 Ultra Office Supplies Product 2024 Office Supplies $787.26 231 2.6 93 SKU-002718
2719 Premium Books Product Special Edition Books $888.31 381 4.9 941 SKU-002719
2720 Professional Toys & Games Product Lite Toys & Games $20.51 222 2.0 306 SKU-002720
2721 Elite Books Product Classic Books $183.98 453 3.4 321 SKU-002721
2722 Professional Office Supplies Product Advanced Office Supplies $551.05 272 1.2 435 SKU-002722
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