Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

7 ms

Page Size

25

Current Page

65 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 65 Results Showing 1601 - 1625 of 24441

ID Name Category Price Stock Rating Reviews SKU
1813 Mega Health & Beauty Product Pro Health & Beauty $103.88 193 3.5 992 SKU-001813
1814 Professional Electronics Product Pro Electronics $579.39 230 4.6 427 SKU-001814
1815 Super Books Product 2024 Books $296.88 389 1.3 219 SKU-001815
1816 Economy Office Supplies Product Lite Office Supplies $728.47 499 3.9 275 SKU-001816
1818 Deluxe Toys & Games Product Classic Toys & Games $84.37 425 3.8 987 SKU-001818
1819 Ultra Sports & Outdoors Product Mini Sports & Outdoors $720.54 56 4.7 47 SKU-001819
1820 Economy Health & Beauty Product Advanced Health & Beauty $28.28 426 2.4 891 SKU-001820
1821 Deluxe Sports & Outdoors Product XL Sports & Outdoors $418.96 66 4.3 292 SKU-001821
1822 Ultra Health & Beauty Product Plus Health & Beauty $171.17 434 4.5 586 SKU-001822
1824 Deluxe Toys & Games Product 2024 Toys & Games $520.41 293 2.1 530 SKU-001824
1825 Elite Home & Garden Product Special Edition Home & Garden $737.10 462 2.9 535 SKU-001825
1826 Super Food & Grocery Product Advanced Food & Grocery $812.18 37 5.0 447 SKU-001826
1827 Professional Automotive Product Mini Automotive $985.72 188 4.2 565 SKU-001827
1828 Premium Electronics Product Plus Electronics $346.50 469 4.0 529 SKU-001828
1829 Mega Home & Garden Product Pro Home & Garden $363.64 8 4.3 417 SKU-001829
1830 Premium Electronics Product 2024 Electronics $574.30 147 2.5 887 SKU-001830
1831 Standard Electronics Product Lite Electronics $282.00 15 1.7 677 SKU-001831
1832 Ultra Electronics Product Special Edition Electronics $162.51 173 2.7 637 SKU-001832
1833 Pro Home & Garden Product Pro Home & Garden $43.79 206 3.4 828 SKU-001833
1834 Ultra Electronics Product Advanced Electronics $220.01 453 1.8 644 SKU-001834
1835 Economy Toys & Games Product Pro Toys & Games $325.73 391 2.0 720 SKU-001835
1836 Mega Health & Beauty Product Advanced Health & Beauty $930.82 329 3.4 955 SKU-001836
1837 Ultra Home & Garden Product Advanced Home & Garden $531.00 116 4.5 150 SKU-001837
1838 Standard Clothing Product Max Clothing $445.98 27 4.7 901 SKU-001838
1839 Elite Toys & Games Product XL Toys & Games $825.11 35 3.3 885 SKU-001839
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