Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

134 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 134 Results Showing 3326 - 3350 of 24441

ID Name Category Price Stock Rating Reviews SKU
3728 Deluxe Automotive Product Mini Automotive $867.12 356 1.9 678 SKU-003728
3730 Pro Food & Grocery Product Lite Food & Grocery $572.94 116 4.1 253 SKU-003730
3731 Pro Food & Grocery Product XL Food & Grocery $489.82 30 4.2 377 SKU-003731
3733 Standard Health & Beauty Product Special Edition Health & Beauty $245.68 443 4.3 383 SKU-003733
3734 Ultra Office Supplies Product Max Office Supplies $227.76 292 1.8 227 SKU-003734
3735 Standard Office Supplies Product Plus Office Supplies $520.12 141 1.7 118 SKU-003735
3736 Professional Sports & Outdoors Product Special Edition Sports & Outdoors $637.90 217 4.6 967 SKU-003736
3737 Elite Clothing Product Pro Clothing $145.20 238 4.0 540 SKU-003737
3738 Deluxe Electronics Product Special Edition Electronics $61.11 491 3.7 705 SKU-003738
3739 Ultra Toys & Games Product Advanced Toys & Games $483.94 325 2.6 851 SKU-003739
3740 Economy Office Supplies Product Max Office Supplies $392.97 122 2.5 182 SKU-003740
3741 Elite Health & Beauty Product Plus Health & Beauty $859.51 117 2.8 915 SKU-003741
3742 Premium Office Supplies Product Max Office Supplies $72.42 465 1.6 171 SKU-003742
3743 Super Home & Garden Product Max Home & Garden $370.84 181 1.6 900 SKU-003743
3744 Mega Electronics Product Lite Electronics $314.80 161 3.5 838 SKU-003744
3745 Pro Health & Beauty Product Advanced Health & Beauty $39.73 90 1.5 198 SKU-003745
3746 Elite Health & Beauty Product Plus Health & Beauty $563.58 300 1.8 252 SKU-003746
3747 Standard Office Supplies Product XL Office Supplies $296.43 411 4.9 515 SKU-003747
3748 Ultra Health & Beauty Product Pro Health & Beauty $149.15 431 2.4 773 SKU-003748
3749 Standard Toys & Games Product Lite Toys & Games $546.02 444 1.3 478 SKU-003749
3750 Professional Electronics Product Advanced Electronics $207.91 371 2.9 626 SKU-003750
3751 Economy Health & Beauty Product Special Edition Health & Beauty $815.48 160 4.2 385 SKU-003751
3752 Economy Office Supplies Product Max Office Supplies $119.35 18 1.4 21 SKU-003752
3753 Economy Health & Beauty Product Mini Health & Beauty $840.86 432 1.9 573 SKU-003753
3754 Professional Clothing Product Special Edition Clothing $328.08 46 2.5 695 SKU-003754
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