Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

50

Current Page

20 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 20 Results Showing 951 - 1000 of 24441

ID Name Category Price Stock Rating Reviews SKU
1069 Ultra Sports & Outdoors Product Plus Sports & Outdoors $68.75 418 4.2 927 SKU-001069
1070 Premium Health & Beauty Product Special Edition Health & Beauty $688.48 183 2.4 253 SKU-001070
1071 Professional Automotive Product Advanced Automotive $352.53 391 1.3 867 SKU-001071
1072 Elite Health & Beauty Product Classic Health & Beauty $114.98 290 3.3 699 SKU-001072
1074 Deluxe Food & Grocery Product Special Edition Food & Grocery $740.81 432 1.8 791 SKU-001074
1075 Standard Books Product 2024 Books $562.61 329 1.6 984 SKU-001075
1076 Premium Office Supplies Product Classic Office Supplies $436.97 63 5.0 140 SKU-001076
1077 Elite Books Product Lite Books $694.75 427 4.5 418 SKU-001077
1078 Economy Automotive Product Lite Automotive $55.89 447 2.1 514 SKU-001078
1079 Standard Automotive Product Mini Automotive $604.53 232 1.9 864 SKU-001079
1080 Premium Office Supplies Product Lite Office Supplies $585.01 314 3.9 79 SKU-001080
1081 Premium Office Supplies Product Lite Office Supplies $389.72 280 3.2 786 SKU-001081
1082 Super Office Supplies Product 2024 Office Supplies $567.39 379 3.1 406 SKU-001082
1083 Standard Clothing Product Special Edition Clothing $388.21 175 1.4 135 SKU-001083
1084 Economy Clothing Product Special Edition Clothing $772.68 398 1.2 224 SKU-001084
1085 Mega Health & Beauty Product Special Edition Health & Beauty $741.15 458 3.6 386 SKU-001085
1086 Deluxe Clothing Product XL Clothing $962.66 133 1.2 679 SKU-001086
1087 Ultra Books Product Max Books $522.00 353 4.0 468 SKU-001087
1088 Pro Sports & Outdoors Product XL Sports & Outdoors $346.24 158 1.0 524 SKU-001088
1089 Standard Automotive Product Pro Automotive $536.27 168 2.4 899 SKU-001089
1090 Elite Electronics Product Lite Electronics $454.77 109 4.3 416 SKU-001090
1091 Ultra Automotive Product 2024 Automotive $973.19 78 4.2 246 SKU-001091
1092 Pro Electronics Product Plus Electronics $949.74 250 3.3 901 SKU-001092
1094 Pro Food & Grocery Product XL Food & Grocery $236.50 49 3.0 214 SKU-001094
1096 Super Toys & Games Product Plus Toys & Games $485.24 251 1.1 906 SKU-001096
1097 Economy Toys & Games Product Classic Toys & Games $847.62 338 3.7 387 SKU-001097
1098 Super Clothing Product Lite Clothing $653.28 54 4.8 898 SKU-001098
1099 Ultra Automotive Product Classic Automotive $756.19 139 4.3 738 SKU-001099
1100 Super Food & Grocery Product XL Food & Grocery $403.13 61 2.9 337 SKU-001100
1101 Standard Office Supplies Product Special Edition Office Supplies $612.03 79 3.8 648 SKU-001101
1102 Standard Toys & Games Product Lite Toys & Games $558.76 135 2.6 664 SKU-001102
1103 Ultra Automotive Product Pro Automotive $499.08 20 4.8 383 SKU-001103
1104 Super Home & Garden Product Pro Home & Garden $780.91 362 4.7 136 SKU-001104
1105 Deluxe Office Supplies Product Plus Office Supplies $966.37 425 1.0 614 SKU-001105
1106 Economy Home & Garden Product Plus Home & Garden $178.79 480 3.7 690 SKU-001106
1108 Elite Books Product 2024 Books $447.91 74 3.9 480 SKU-001108
1109 Premium Clothing Product Special Edition Clothing $197.08 339 4.7 505 SKU-001109
1110 Deluxe Electronics Product Pro Electronics $683.61 87 4.8 320 SKU-001110
1111 Pro Clothing Product XL Clothing $680.94 194 4.4 44 SKU-001111
1112 Elite Food & Grocery Product Lite Food & Grocery $831.54 374 3.8 31 SKU-001112
1115 Super Books Product Max Books $931.87 326 4.7 954 SKU-001115
1116 Deluxe Office Supplies Product Special Edition Office Supplies $700.17 133 1.9 453 SKU-001116
1118 Economy Electronics Product Max Electronics $492.68 184 3.8 932 SKU-001118
1119 Deluxe Food & Grocery Product 2024 Food & Grocery $471.44 127 4.4 822 SKU-001119
1121 Premium Clothing Product Special Edition Clothing $350.45 351 2.4 811 SKU-001121
1122 Elite Food & Grocery Product XL Food & Grocery $486.01 246 4.1 172 SKU-001122
1123 Elite Health & Beauty Product Special Edition Health & Beauty $626.48 457 4.5 193 SKU-001123
1124 Professional Health & Beauty Product Max Health & Beauty $106.42 36 2.5 194 SKU-001124
1125 Super Food & Grocery Product Plus Food & Grocery $939.23 122 3.0 299 SKU-001125
1126 Ultra Home & Garden Product Special Edition Home & Garden $160.25 211 1.8 588 SKU-001126
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