Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

25

Current Page

61 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 61 Results Showing 1501 - 1525 of 24441

ID Name Category Price Stock Rating Reviews SKU
1701 Pro Toys & Games Product Lite Toys & Games $625.61 15 1.5 439 SKU-001701
1702 Ultra Automotive Product Max Automotive $322.24 419 1.9 863 SKU-001702
1703 Mega Food & Grocery Product Advanced Food & Grocery $512.19 321 2.9 584 SKU-001703
1704 Super Home & Garden Product Mini Home & Garden $539.29 95 2.5 652 SKU-001704
1705 Professional Books Product XL Books $729.96 69 2.3 667 SKU-001705
1706 Premium Clothing Product Classic Clothing $187.90 121 4.0 474 SKU-001706
1707 Elite Electronics Product 2024 Electronics $971.47 97 3.3 694 SKU-001707
1708 Pro Home & Garden Product Pro Home & Garden $617.50 230 4.1 243 SKU-001708
1709 Mega Clothing Product Mini Clothing $948.91 425 1.8 456 SKU-001709
1710 Ultra Books Product Pro Books $284.60 353 1.6 515 SKU-001710
1711 Standard Home & Garden Product Classic Home & Garden $265.70 335 3.2 541 SKU-001711
1712 Pro Toys & Games Product Special Edition Toys & Games $550.50 138 4.0 809 SKU-001712
1713 Pro Books Product 2024 Books $96.52 59 3.7 236 SKU-001713
1714 Super Automotive Product Plus Automotive $902.71 184 4.3 330 SKU-001714
1716 Super Health & Beauty Product Max Health & Beauty $473.92 482 4.9 692 SKU-001716
1718 Elite Home & Garden Product Pro Home & Garden $328.40 25 4.2 212 SKU-001718
1719 Ultra Toys & Games Product Plus Toys & Games $723.18 200 4.3 914 SKU-001719
1720 Super Books Product Advanced Books $661.11 294 3.9 799 SKU-001720
1722 Super Toys & Games Product Mini Toys & Games $737.99 128 1.5 603 SKU-001722
1723 Ultra Health & Beauty Product Lite Health & Beauty $488.67 325 1.7 938 SKU-001723
1724 Deluxe Health & Beauty Product Lite Health & Beauty $19.27 379 2.0 6 SKU-001724
1725 Premium Books Product Classic Books $768.25 420 2.8 260 SKU-001725
1726 Super Clothing Product Max Clothing $477.79 246 3.1 421 SKU-001726
1727 Premium Home & Garden Product Classic Home & Garden $320.40 425 1.5 541 SKU-001727
1728 Elite Automotive Product Advanced Automotive $239.56 185 3.3 189 SKU-001728
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