Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

50

Current Page

60 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 60 Results Showing 2951 - 3000 of 24441

ID Name Category Price Stock Rating Reviews SKU
3313 Mega Electronics Product Lite Electronics $331.73 285 3.8 561 SKU-003313
3314 Deluxe Food & Grocery Product Plus Food & Grocery $868.60 98 2.2 764 SKU-003314
3315 Standard Automotive Product XL Automotive $360.23 157 3.1 959 SKU-003315
3316 Deluxe Electronics Product Pro Electronics $405.64 219 2.5 358 SKU-003316
3317 Super Toys & Games Product Classic Toys & Games $745.16 413 2.6 186 SKU-003317
3319 Mega Food & Grocery Product Pro Food & Grocery $392.05 481 3.8 62 SKU-003319
3320 Economy Food & Grocery Product Lite Food & Grocery $311.75 49 1.2 132 SKU-003320
3321 Super Automotive Product 2024 Automotive $273.46 254 4.3 701 SKU-003321
3322 Mega Food & Grocery Product XL Food & Grocery $582.83 259 1.5 233 SKU-003322
3323 Deluxe Food & Grocery Product XL Food & Grocery $303.80 116 2.9 817 SKU-003323
3324 Premium Sports & Outdoors Product Advanced Sports & Outdoors $671.18 162 2.1 633 SKU-003324
3325 Pro Electronics Product Special Edition Electronics $337.35 369 1.0 837 SKU-003325
3327 Pro Electronics Product 2024 Electronics $586.67 408 3.4 222 SKU-003327
3328 Deluxe Clothing Product 2024 Clothing $856.07 302 1.4 323 SKU-003328
3329 Professional Office Supplies Product Classic Office Supplies $553.96 205 2.4 115 SKU-003329
3330 Deluxe Books Product Special Edition Books $398.52 270 1.9 655 SKU-003330
3331 Standard Office Supplies Product Mini Office Supplies $917.36 364 3.6 130 SKU-003331
3332 Pro Food & Grocery Product Pro Food & Grocery $240.76 411 4.0 730 SKU-003332
3334 Elite Toys & Games Product Plus Toys & Games $532.47 358 3.6 723 SKU-003334
3335 Premium Office Supplies Product Mini Office Supplies $698.69 445 2.8 760 SKU-003335
3336 Mega Toys & Games Product Pro Toys & Games $169.48 454 3.2 794 SKU-003336
3337 Ultra Automotive Product 2024 Automotive $482.64 476 3.7 284 SKU-003337
3338 Professional Office Supplies Product Special Edition Office Supplies $841.31 3 3.2 850 SKU-003338
3339 Ultra Office Supplies Product 2024 Office Supplies $607.74 423 1.7 416 SKU-003339
3340 Mega Home & Garden Product Mini Home & Garden $451.60 462 1.8 160 SKU-003340
3341 Pro Office Supplies Product 2024 Office Supplies $805.62 296 3.6 983 SKU-003341
3342 Ultra Home & Garden Product Max Home & Garden $209.08 98 4.2 798 SKU-003342
3343 Mega Home & Garden Product Advanced Home & Garden $822.85 480 2.8 400 SKU-003343
3344 Economy Health & Beauty Product 2024 Health & Beauty $838.50 97 1.1 755 SKU-003344
3345 Deluxe Automotive Product Advanced Automotive $216.35 489 1.5 760 SKU-003345
3346 Economy Office Supplies Product 2024 Office Supplies $967.29 447 2.3 578 SKU-003346
3347 Deluxe Health & Beauty Product Advanced Health & Beauty $117.89 174 4.9 660 SKU-003347
3348 Pro Office Supplies Product Advanced Office Supplies $108.94 359 3.3 194 SKU-003348
3349 Mega Automotive Product Max Automotive $190.03 35 2.0 694 SKU-003349
3350 Professional Books Product Max Books $143.08 312 2.3 371 SKU-003350
3351 Pro Home & Garden Product Special Edition Home & Garden $782.92 191 3.3 214 SKU-003351
3352 Mega Office Supplies Product Advanced Office Supplies $296.48 38 3.3 520 SKU-003352
3353 Ultra Food & Grocery Product Lite Food & Grocery $793.21 14 2.2 601 SKU-003353
3354 Elite Books Product Max Books $746.70 29 4.4 680 SKU-003354
3355 Premium Books Product 2024 Books $681.00 447 4.4 350 SKU-003355
3356 Ultra Office Supplies Product Max Office Supplies $919.03 329 4.3 524 SKU-003356
3357 Ultra Books Product Plus Books $529.08 418 1.4 228 SKU-003357
3358 Mega Automotive Product Lite Automotive $849.29 109 1.3 321 SKU-003358
3360 Mega Automotive Product Plus Automotive $309.44 310 5.0 802 SKU-003360
3361 Professional Home & Garden Product Advanced Home & Garden $795.36 142 1.1 110 SKU-003361
3362 Pro Electronics Product Classic Electronics $567.72 113 3.7 531 SKU-003362
3363 Mega Food & Grocery Product Mini Food & Grocery $478.48 208 3.4 715 SKU-003363
3364 Deluxe Food & Grocery Product Lite Food & Grocery $486.87 237 1.4 234 SKU-003364
3365 Pro Automotive Product Lite Automotive $838.41 369 2.5 909 SKU-003365
3366 Pro Automotive Product 2024 Automotive $37.83 103 2.1 183 SKU-003366
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