Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

25

Current Page

63 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 63 Results Showing 1551 - 1575 of 24441

ID Name Category Price Stock Rating Reviews SKU
1758 Professional Toys & Games Product 2024 Toys & Games $736.79 132 1.3 466 SKU-001758
1759 Premium Automotive Product Mini Automotive $230.14 295 3.5 33 SKU-001759
1760 Mega Office Supplies Product Plus Office Supplies $500.34 165 3.4 658 SKU-001760
1761 Economy Clothing Product XL Clothing $830.90 20 1.6 600 SKU-001761
1764 Standard Home & Garden Product XL Home & Garden $339.58 130 1.2 815 SKU-001764
1765 Deluxe Health & Beauty Product Mini Health & Beauty $298.20 78 3.3 617 SKU-001765
1766 Standard Sports & Outdoors Product Pro Sports & Outdoors $358.89 206 1.6 739 SKU-001766
1767 Super Office Supplies Product Special Edition Office Supplies $913.66 34 2.3 953 SKU-001767
1768 Deluxe Automotive Product Lite Automotive $929.36 479 4.3 61 SKU-001768
1769 Deluxe Office Supplies Product Pro Office Supplies $520.91 325 3.2 233 SKU-001769
1770 Professional Food & Grocery Product 2024 Food & Grocery $637.46 316 2.0 243 SKU-001770
1771 Deluxe Automotive Product Mini Automotive $116.68 21 1.9 235 SKU-001771
1772 Pro Books Product Advanced Books $977.22 103 4.3 727 SKU-001772
1773 Premium Toys & Games Product Pro Toys & Games $180.80 199 3.2 132 SKU-001773
1774 Super Toys & Games Product Classic Toys & Games $61.46 192 3.0 91 SKU-001774
1775 Economy Automotive Product 2024 Automotive $98.41 206 3.6 479 SKU-001775
1776 Elite Books Product Special Edition Books $67.82 257 3.4 670 SKU-001776
1777 Professional Food & Grocery Product Classic Food & Grocery $454.47 32 3.3 434 SKU-001777
1778 Ultra Office Supplies Product Mini Office Supplies $195.32 361 2.9 901 SKU-001778
1779 Premium Books Product Max Books $201.94 219 2.6 660 SKU-001779
1780 Ultra Sports & Outdoors Product Mini Sports & Outdoors $753.97 438 3.3 404 SKU-001780
1781 Super Health & Beauty Product Plus Health & Beauty $417.54 317 2.9 413 SKU-001781
1782 Super Automotive Product Advanced Automotive $507.67 180 3.6 333 SKU-001782
1783 Ultra Electronics Product Classic Electronics $420.63 376 2.6 100 SKU-001783
1785 Deluxe Books Product Mini Books $523.71 491 4.3 381 SKU-001785
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