Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

67 ms

Page Size

25

Current Page

100 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 100 Results Showing 2476 - 2500 of 24441

ID Name Category Price Stock Rating Reviews SKU
2779 Professional Health & Beauty Product 2024 Health & Beauty $237.56 471 1.9 616 SKU-002779
2780 Economy Home & Garden Product Special Edition Home & Garden $884.63 185 4.5 898 SKU-002780
2781 Ultra Sports & Outdoors Product Advanced Sports & Outdoors $413.04 468 3.2 445 SKU-002781
2782 Economy Toys & Games Product Classic Toys & Games $404.35 425 2.2 656 SKU-002782
2783 Elite Food & Grocery Product Classic Food & Grocery $392.80 188 4.8 185 SKU-002783
2784 Economy Toys & Games Product Lite Toys & Games $479.34 254 2.0 112 SKU-002784
2786 Pro Automotive Product XL Automotive $425.26 216 2.0 372 SKU-002786
2787 Professional Office Supplies Product Max Office Supplies $332.33 339 3.4 47 SKU-002787
2788 Economy Sports & Outdoors Product Classic Sports & Outdoors $554.87 365 3.7 872 SKU-002788
2789 Elite Home & Garden Product Advanced Home & Garden $213.56 150 3.6 714 SKU-002789
2790 Mega Electronics Product Plus Electronics $782.26 376 2.5 463 SKU-002790
2791 Ultra Home & Garden Product Mini Home & Garden $93.98 297 3.8 831 SKU-002791
2793 Ultra Clothing Product XL Clothing $107.60 226 3.9 444 SKU-002793
2794 Professional Food & Grocery Product Plus Food & Grocery $504.16 32 4.2 540 SKU-002794
2795 Mega Health & Beauty Product Classic Health & Beauty $277.44 206 4.3 726 SKU-002795
2796 Professional Food & Grocery Product Plus Food & Grocery $586.76 463 2.3 29 SKU-002796
2797 Deluxe Office Supplies Product Max Office Supplies $33.31 186 5.0 160 SKU-002797
2799 Economy Automotive Product Max Automotive $101.67 437 3.6 836 SKU-002799
2800 Super Home & Garden Product Classic Home & Garden $294.14 346 3.7 858 SKU-002800
2801 Elite Home & Garden Product Mini Home & Garden $438.24 380 1.6 305 SKU-002801
2802 Mega Automotive Product Lite Automotive $106.95 253 1.1 401 SKU-002802
2803 Premium Clothing Product Special Edition Clothing $901.35 480 4.2 517 SKU-002803
2804 Premium Automotive Product XL Automotive $845.96 113 1.3 880 SKU-002804
2805 Pro Sports & Outdoors Product Special Edition Sports & Outdoors $271.47 211 2.8 479 SKU-002805
2806 Standard Health & Beauty Product Advanced Health & Beauty $43.22 173 4.9 158 SKU-002806
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