Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

97 ms

Page Size

50

Current Page

62 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 62 Results Showing 3051 - 3100 of 24441

ID Name Category Price Stock Rating Reviews SKU
3426 Premium Toys & Games Product XL Toys & Games $731.48 426 4.5 276 SKU-003426
3427 Standard Office Supplies Product XL Office Supplies $748.23 294 4.8 636 SKU-003427
3428 Elite Books Product Lite Books $970.99 436 3.8 540 SKU-003428
3429 Premium Clothing Product 2024 Clothing $125.53 110 2.8 176 SKU-003429
3430 Super Sports & Outdoors Product Max Sports & Outdoors $551.07 431 3.6 108 SKU-003430
3431 Pro Office Supplies Product Mini Office Supplies $36.03 492 1.7 371 SKU-003431
3432 Premium Office Supplies Product Advanced Office Supplies $878.41 198 3.9 863 SKU-003432
3433 Deluxe Health & Beauty Product Pro Health & Beauty $719.54 494 1.8 24 SKU-003433
3434 Deluxe Home & Garden Product XL Home & Garden $112.98 279 5.0 444 SKU-003434
3435 Elite Electronics Product Pro Electronics $323.41 395 2.0 592 SKU-003435
3436 Standard Food & Grocery Product Classic Food & Grocery $444.17 312 4.0 919 SKU-003436
3437 Super Health & Beauty Product Advanced Health & Beauty $562.28 84 4.1 948 SKU-003437
3438 Standard Food & Grocery Product Max Food & Grocery $611.03 194 3.4 203 SKU-003438
3440 Standard Toys & Games Product 2024 Toys & Games $344.00 125 3.9 307 SKU-003440
3441 Ultra Clothing Product Mini Clothing $943.19 285 3.0 320 SKU-003441
3442 Mega Books Product Pro Books $943.74 329 1.8 355 SKU-003442
3444 Standard Health & Beauty Product Mini Health & Beauty $568.71 127 3.4 674 SKU-003444
3446 Super Electronics Product Classic Electronics $779.68 246 1.8 251 SKU-003446
3448 Economy Food & Grocery Product Max Food & Grocery $326.45 448 4.7 804 SKU-003448
3449 Ultra Automotive Product Special Edition Automotive $228.49 261 1.6 137 SKU-003449
3450 Economy Clothing Product Advanced Clothing $795.51 451 2.3 272 SKU-003450
3451 Professional Office Supplies Product Pro Office Supplies $966.79 222 3.2 324 SKU-003451
3452 Mega Home & Garden Product Max Home & Garden $471.76 232 2.5 561 SKU-003452
3453 Economy Automotive Product Special Edition Automotive $773.13 4 2.3 186 SKU-003453
3454 Economy Health & Beauty Product XL Health & Beauty $96.12 451 2.4 505 SKU-003454
3455 Standard Books Product XL Books $48.06 299 4.8 271 SKU-003455
3456 Mega Health & Beauty Product Pro Health & Beauty $806.16 360 3.5 967 SKU-003456
3457 Pro Food & Grocery Product Pro Food & Grocery $469.60 96 1.5 476 SKU-003457
3458 Mega Health & Beauty Product Lite Health & Beauty $427.77 367 4.4 520 SKU-003458
3459 Premium Food & Grocery Product Lite Food & Grocery $376.59 289 4.6 464 SKU-003459
3460 Premium Health & Beauty Product Plus Health & Beauty $102.43 274 4.3 557 SKU-003460
3461 Deluxe Books Product Classic Books $371.28 89 4.6 844 SKU-003461
3462 Economy Health & Beauty Product 2024 Health & Beauty $31.25 216 3.8 398 SKU-003462
3463 Elite Health & Beauty Product Pro Health & Beauty $223.13 109 2.8 427 SKU-003463
3464 Deluxe Sports & Outdoors Product 2024 Sports & Outdoors $356.86 270 2.3 339 SKU-003464
3465 Premium Electronics Product Pro Electronics $939.15 357 1.2 898 SKU-003465
3466 Deluxe Toys & Games Product Advanced Toys & Games $933.88 392 3.1 64 SKU-003466
3467 Elite Sports & Outdoors Product Advanced Sports & Outdoors $383.95 102 4.0 106 SKU-003467
3468 Ultra Toys & Games Product Lite Toys & Games $72.49 181 3.8 66 SKU-003468
3469 Elite Electronics Product Max Electronics $256.52 276 4.9 305 SKU-003469
3470 Professional Food & Grocery Product Classic Food & Grocery $370.12 228 3.5 174 SKU-003470
3471 Professional Books Product Mini Books $740.08 360 4.9 52 SKU-003471
3472 Super Toys & Games Product Plus Toys & Games $437.88 356 1.4 530 SKU-003472
3473 Elite Clothing Product Max Clothing $614.29 6 1.4 762 SKU-003473
3474 Pro Health & Beauty Product Special Edition Health & Beauty $460.30 321 3.7 573 SKU-003474
3475 Mega Food & Grocery Product Special Edition Food & Grocery $866.32 96 5.0 965 SKU-003475
3476 Ultra Office Supplies Product Classic Office Supplies $965.40 95 4.2 511 SKU-003476
3477 Pro Health & Beauty Product Advanced Health & Beauty $937.95 399 3.6 524 SKU-003477
3478 Economy Home & Garden Product Pro Home & Garden $554.98 129 2.0 858 SKU-003478
3479 Ultra Toys & Games Product Mini Toys & Games $422.72 124 3.8 129 SKU-003479
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