Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

50

Current Page

19 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 19 Results Showing 901 - 950 of 24441

ID Name Category Price Stock Rating Reviews SKU
1009 Elite Books Product Lite Books $452.43 458 3.3 256 SKU-001009
1010 Mega Office Supplies Product Lite Office Supplies $655.10 376 3.4 896 SKU-001010
1012 Pro Food & Grocery Product Classic Food & Grocery $960.45 146 1.4 241 SKU-001012
1013 Standard Electronics Product XL Electronics $653.71 323 1.8 572 SKU-001013
1015 Elite Toys & Games Product Max Toys & Games $661.83 85 2.7 689 SKU-001015
1016 Economy Automotive Product Pro Automotive $569.78 33 4.4 305 SKU-001016
1017 Elite Electronics Product Classic Electronics $573.84 455 1.4 626 SKU-001017
1018 Ultra Home & Garden Product 2024 Home & Garden $365.65 86 2.4 686 SKU-001018
1019 Premium Home & Garden Product Classic Home & Garden $863.39 467 3.0 837 SKU-001019
1020 Elite Home & Garden Product Lite Home & Garden $464.07 7 2.5 99 SKU-001020
1021 Deluxe Automotive Product 2024 Automotive $687.74 386 3.2 235 SKU-001021
1022 Super Sports & Outdoors Product XL Sports & Outdoors $266.40 428 3.0 97 SKU-001022
1023 Elite Toys & Games Product Special Edition Toys & Games $645.19 172 2.6 970 SKU-001023
1025 Mega Home & Garden Product Advanced Home & Garden $240.08 209 2.7 258 SKU-001025
1027 Elite Health & Beauty Product Plus Health & Beauty $37.70 104 3.6 764 SKU-001027
1028 Ultra Food & Grocery Product XL Food & Grocery $107.16 437 2.4 153 SKU-001028
1029 Deluxe Books Product Pro Books $199.95 425 2.4 64 SKU-001029
1032 Premium Food & Grocery Product Mini Food & Grocery $147.32 29 4.8 121 SKU-001032
1034 Economy Home & Garden Product Special Edition Home & Garden $703.11 387 3.8 319 SKU-001034
1035 Super Health & Beauty Product Max Health & Beauty $307.22 300 4.7 534 SKU-001035
1036 Deluxe Toys & Games Product Advanced Toys & Games $962.05 481 1.8 604 SKU-001036
1037 Ultra Electronics Product Classic Electronics $499.36 50 4.0 791 SKU-001037
1038 Elite Health & Beauty Product Mini Health & Beauty $890.33 237 4.5 702 SKU-001038
1039 Professional Automotive Product Lite Automotive $985.93 322 2.9 763 SKU-001039
1040 Pro Home & Garden Product Special Edition Home & Garden $834.34 27 3.3 157 SKU-001040
1041 Premium Electronics Product Classic Electronics $820.99 50 4.3 854 SKU-001041
1042 Elite Toys & Games Product Classic Toys & Games $645.04 167 4.7 267 SKU-001042
1043 Elite Health & Beauty Product Special Edition Health & Beauty $182.90 133 2.9 380 SKU-001043
1044 Standard Electronics Product Pro Electronics $480.76 42 1.3 47 SKU-001044
1045 Premium Books Product Max Books $213.60 340 2.2 667 SKU-001045
1046 Standard Home & Garden Product XL Home & Garden $505.25 439 1.5 574 SKU-001046
1047 Standard Food & Grocery Product Max Food & Grocery $658.65 464 1.3 766 SKU-001047
1048 Mega Automotive Product Lite Automotive $120.25 261 2.5 265 SKU-001048
1049 Super Home & Garden Product Pro Home & Garden $757.73 362 3.1 912 SKU-001049
1050 Premium Books Product Pro Books $824.57 126 1.8 849 SKU-001050
1051 Economy Office Supplies Product Max Office Supplies $909.78 81 2.8 356 SKU-001051
1052 Mega Office Supplies Product Plus Office Supplies $547.15 335 2.4 230 SKU-001052
1053 Elite Electronics Product Mini Electronics $55.59 124 4.6 662 SKU-001053
1054 Professional Automotive Product Lite Automotive $928.01 214 1.7 517 SKU-001054
1055 Pro Health & Beauty Product Plus Health & Beauty $699.40 434 1.5 808 SKU-001055
1056 Economy Electronics Product Advanced Electronics $926.45 411 1.6 574 SKU-001056
1057 Professional Food & Grocery Product 2024 Food & Grocery $70.10 133 1.0 298 SKU-001057
1059 Standard Books Product Special Edition Books $97.10 433 1.0 901 SKU-001059
1061 Ultra Clothing Product Special Edition Clothing $718.70 269 3.1 526 SKU-001061
1062 Professional Home & Garden Product XL Home & Garden $737.42 90 3.5 695 SKU-001062
1064 Premium Toys & Games Product XL Toys & Games $224.38 379 2.3 0 SKU-001064
1065 Mega Home & Garden Product Advanced Home & Garden $499.27 121 2.3 586 SKU-001065
1066 Elite Clothing Product Mini Clothing $816.89 199 3.4 607 SKU-001066
1067 Elite Sports & Outdoors Product Advanced Sports & Outdoors $585.66 384 3.3 65 SKU-001067
1068 Economy Clothing Product Pro Clothing $928.88 310 2.0 783 SKU-001068
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