Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

25

Current Page

104 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 104 Results Showing 2576 - 2600 of 24441

ID Name Category Price Stock Rating Reviews SKU
2891 Standard Books Product Pro Books $690.89 303 3.9 296 SKU-002891
2893 Deluxe Books Product 2024 Books $523.26 314 3.9 316 SKU-002893
2894 Pro Books Product Special Edition Books $651.97 118 3.4 3 SKU-002894
2895 Super Automotive Product Lite Automotive $463.73 111 4.1 277 SKU-002895
2896 Economy Food & Grocery Product Mini Food & Grocery $488.68 357 2.7 533 SKU-002896
2897 Professional Health & Beauty Product Classic Health & Beauty $438.19 426 3.9 114 SKU-002897
2898 Super Office Supplies Product Pro Office Supplies $954.52 16 2.7 54 SKU-002898
2899 Economy Clothing Product Lite Clothing $427.02 104 4.5 311 SKU-002899
2900 Pro Books Product Plus Books $851.84 215 3.8 124 SKU-002900
2901 Elite Toys & Games Product Mini Toys & Games $428.15 367 3.7 376 SKU-002901
2902 Super Automotive Product Plus Automotive $97.90 30 1.5 965 SKU-002902
2903 Mega Toys & Games Product Pro Toys & Games $538.30 345 4.6 837 SKU-002903
2904 Elite Office Supplies Product XL Office Supplies $739.85 469 3.2 275 SKU-002904
2905 Standard Home & Garden Product XL Home & Garden $502.82 30 3.1 19 SKU-002905
2906 Deluxe Automotive Product Special Edition Automotive $142.08 327 2.1 765 SKU-002906
2907 Mega Books Product 2024 Books $748.01 250 2.3 228 SKU-002907
2908 Super Health & Beauty Product 2024 Health & Beauty $320.51 167 2.1 218 SKU-002908
2909 Professional Books Product Mini Books $115.32 23 3.5 736 SKU-002909
2910 Pro Home & Garden Product Pro Home & Garden $722.52 166 1.0 49 SKU-002910
2911 Mega Food & Grocery Product Lite Food & Grocery $658.08 201 3.7 408 SKU-002911
2912 Mega Toys & Games Product XL Toys & Games $480.47 381 4.7 679 SKU-002912
2913 Deluxe Office Supplies Product Mini Office Supplies $792.32 128 3.9 580 SKU-002913
2914 Elite Home & Garden Product Pro Home & Garden $333.55 460 2.0 359 SKU-002914
2915 Super Sports & Outdoors Product Lite Sports & Outdoors $818.68 162 2.6 979 SKU-002915
2916 Standard Health & Beauty Product Advanced Health & Beauty $83.29 409 2.7 977 SKU-002916
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