Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

48 ms

Page Size

25

Current Page

32 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 32 Results Showing 776 - 800 of 24441

ID Name Category Price Stock Rating Reviews SKU
867 Professional Clothing Product Advanced Clothing $14.88 395 3.1 215 SKU-000867
868 Standard Clothing Product Max Clothing $325.03 98 4.4 391 SKU-000868
869 Premium Sports & Outdoors Product Mini Sports & Outdoors $11.66 382 2.6 573 SKU-000869
870 Elite Books Product Mini Books $314.88 437 1.1 122 SKU-000870
871 Economy Clothing Product Special Edition Clothing $321.96 358 1.8 863 SKU-000871
872 Deluxe Home & Garden Product Classic Home & Garden $650.05 309 3.4 31 SKU-000872
874 Standard Office Supplies Product Plus Office Supplies $798.82 275 1.7 412 SKU-000874
875 Deluxe Food & Grocery Product XL Food & Grocery $115.11 142 2.4 341 SKU-000875
876 Economy Sports & Outdoors Product Classic Sports & Outdoors $920.67 484 4.7 526 SKU-000876
877 Professional Automotive Product Plus Automotive $326.52 9 2.1 22 SKU-000877
878 Elite Toys & Games Product XL Toys & Games $940.28 21 3.8 284 SKU-000878
879 Elite Clothing Product Plus Clothing $452.39 216 1.3 75 SKU-000879
880 Standard Home & Garden Product XL Home & Garden $665.48 414 4.8 71 SKU-000880
881 Professional Electronics Product Lite Electronics $487.59 308 5.0 730 SKU-000881
882 Economy Home & Garden Product Plus Home & Garden $562.90 140 2.3 200 SKU-000882
883 Deluxe Electronics Product 2024 Electronics $842.38 149 2.9 164 SKU-000883
884 Economy Electronics Product XL Electronics $761.68 484 2.6 35 SKU-000884
886 Deluxe Toys & Games Product Max Toys & Games $856.26 167 1.4 314 SKU-000886
887 Economy Sports & Outdoors Product XL Sports & Outdoors $831.35 125 3.1 59 SKU-000887
888 Super Toys & Games Product Classic Toys & Games $385.08 348 3.6 908 SKU-000888
889 Mega Home & Garden Product Special Edition Home & Garden $387.25 367 1.4 616 SKU-000889
890 Super Sports & Outdoors Product Advanced Sports & Outdoors $785.38 275 1.7 866 SKU-000890
891 Economy Food & Grocery Product Advanced Food & Grocery $855.25 127 3.4 734 SKU-000891
892 Standard Food & Grocery Product Classic Food & Grocery $284.89 277 4.0 557 SKU-000892
893 Elite Food & Grocery Product Max Food & Grocery $843.26 379 2.0 920 SKU-000893
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