Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

33 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 33 Results Showing 801 - 825 of 24441

ID Name Category Price Stock Rating Reviews SKU
894 Ultra Automotive Product Mini Automotive $315.96 56 4.8 815 SKU-000894
895 Ultra Home & Garden Product Special Edition Home & Garden $408.76 126 1.8 217 SKU-000895
896 Super Food & Grocery Product XL Food & Grocery $550.85 392 2.0 332 SKU-000896
897 Standard Food & Grocery Product Classic Food & Grocery $601.19 335 3.4 784 SKU-000897
899 Deluxe Electronics Product Lite Electronics $352.87 425 4.9 402 SKU-000899
900 Premium Home & Garden Product Special Edition Home & Garden $258.80 57 3.3 167 SKU-000900
901 Deluxe Electronics Product Max Electronics $399.46 422 4.4 949 SKU-000901
903 Deluxe Toys & Games Product Lite Toys & Games $892.13 258 2.1 693 SKU-000903
904 Super Home & Garden Product Classic Home & Garden $210.57 89 1.3 110 SKU-000904
905 Premium Clothing Product Pro Clothing $462.39 241 1.1 175 SKU-000905
906 Economy Home & Garden Product Mini Home & Garden $244.59 470 2.3 636 SKU-000906
907 Elite Home & Garden Product Advanced Home & Garden $774.40 123 3.8 875 SKU-000907
908 Professional Office Supplies Product Classic Office Supplies $729.55 180 2.9 949 SKU-000908
910 Economy Home & Garden Product Max Home & Garden $822.57 339 2.9 3 SKU-000910
911 Elite Health & Beauty Product XL Health & Beauty $854.05 316 4.3 334 SKU-000911
912 Economy Electronics Product Mini Electronics $921.11 406 2.0 665 SKU-000912
913 Standard Books Product 2024 Books $100.01 45 1.5 424 SKU-000913
915 Elite Clothing Product Mini Clothing $56.66 319 2.4 168 SKU-000915
917 Pro Electronics Product Max Electronics $15.74 187 3.3 645 SKU-000917
918 Economy Toys & Games Product 2024 Toys & Games $475.64 187 4.0 835 SKU-000918
919 Economy Electronics Product Lite Electronics $69.26 18 1.7 56 SKU-000919
921 Professional Food & Grocery Product XL Food & Grocery $687.41 349 3.8 148 SKU-000921
922 Deluxe Toys & Games Product Lite Toys & Games $20.83 152 1.2 16 SKU-000922
923 Pro Food & Grocery Product Advanced Food & Grocery $784.13 312 2.5 840 SKU-000923
924 Premium Health & Beauty Product 2024 Health & Beauty $150.93 3 1.3 741 SKU-000924
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