Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

70 ms

Page Size

25

Current Page

102 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 102 Results Showing 2526 - 2550 of 24441

ID Name Category Price Stock Rating Reviews SKU
2837 Elite Sports & Outdoors Product 2024 Sports & Outdoors $779.23 363 5.0 56 SKU-002837
2838 Economy Clothing Product Advanced Clothing $368.50 455 1.6 244 SKU-002838
2839 Ultra Toys & Games Product Pro Toys & Games $193.58 309 1.9 832 SKU-002839
2840 Economy Health & Beauty Product Advanced Health & Beauty $719.00 384 4.6 805 SKU-002840
2841 Professional Food & Grocery Product Advanced Food & Grocery $11.07 142 3.6 339 SKU-002841
2842 Mega Home & Garden Product Max Home & Garden $883.59 320 3.6 794 SKU-002842
2843 Professional Health & Beauty Product Lite Health & Beauty $715.33 462 1.4 569 SKU-002843
2844 Premium Food & Grocery Product Max Food & Grocery $905.60 388 1.2 907 SKU-002844
2845 Super Books Product Plus Books $13.99 354 4.4 211 SKU-002845
2846 Deluxe Electronics Product Plus Electronics $690.37 127 4.8 860 SKU-002846
2847 Professional Toys & Games Product Lite Toys & Games $621.74 264 3.1 25 SKU-002847
2848 Economy Clothing Product Advanced Clothing $318.31 412 3.5 267 SKU-002848
2849 Elite Automotive Product 2024 Automotive $470.39 398 2.5 184 SKU-002849
2850 Pro Toys & Games Product Pro Toys & Games $195.91 338 2.9 573 SKU-002850
2851 Ultra Automotive Product Plus Automotive $537.32 367 3.9 451 SKU-002851
2852 Deluxe Electronics Product Plus Electronics $804.00 468 2.3 275 SKU-002852
2853 Premium Sports & Outdoors Product 2024 Sports & Outdoors $319.84 34 4.1 111 SKU-002853
2854 Deluxe Home & Garden Product Plus Home & Garden $688.93 385 1.1 978 SKU-002854
2856 Pro Health & Beauty Product XL Health & Beauty $201.92 384 2.4 807 SKU-002856
2857 Ultra Electronics Product Special Edition Electronics $272.53 321 2.2 428 SKU-002857
2858 Economy Electronics Product Lite Electronics $121.71 49 1.8 763 SKU-002858
2859 Deluxe Toys & Games Product Special Edition Toys & Games $442.24 59 2.7 685 SKU-002859
2860 Standard Toys & Games Product 2024 Toys & Games $969.10 369 2.3 638 SKU-002860
2861 Professional Electronics Product Plus Electronics $694.82 392 4.4 948 SKU-002861
2862 Economy Home & Garden Product Plus Home & Garden $432.78 377 3.6 146 SKU-002862
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