Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

50

Current Page

44 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 44 Results Showing 2151 - 2200 of 24441

ID Name Category Price Stock Rating Reviews SKU
2420 Ultra Sports & Outdoors Product XL Sports & Outdoors $125.30 112 2.5 931 SKU-002420
2421 Economy Electronics Product Special Edition Electronics $722.52 108 3.2 542 SKU-002421
2422 Super Sports & Outdoors Product XL Sports & Outdoors $276.84 475 4.5 303 SKU-002422
2423 Standard Food & Grocery Product Max Food & Grocery $959.24 248 2.9 15 SKU-002423
2424 Ultra Clothing Product Pro Clothing $484.10 415 1.2 490 SKU-002424
2425 Mega Toys & Games Product Plus Toys & Games $915.38 401 1.6 506 SKU-002425
2426 Elite Books Product Plus Books $983.89 22 4.5 415 SKU-002426
2427 Ultra Home & Garden Product Max Home & Garden $174.99 37 2.2 173 SKU-002427
2428 Professional Food & Grocery Product Plus Food & Grocery $591.99 236 2.5 400 SKU-002428
2429 Premium Home & Garden Product Max Home & Garden $180.20 207 2.9 694 SKU-002429
2431 Super Toys & Games Product Plus Toys & Games $801.52 146 2.0 122 SKU-002431
2432 Professional Books Product XL Books $412.91 207 2.8 43 SKU-002432
2433 Super Toys & Games Product Lite Toys & Games $299.57 219 2.3 801 SKU-002433
2434 Elite Electronics Product Advanced Electronics $928.19 270 2.6 47 SKU-002434
2435 Standard Food & Grocery Product Pro Food & Grocery $811.81 58 3.3 546 SKU-002435
2436 Ultra Office Supplies Product Mini Office Supplies $91.97 424 2.5 295 SKU-002436
2437 Pro Clothing Product Special Edition Clothing $840.15 424 2.3 659 SKU-002437
2438 Ultra Toys & Games Product Plus Toys & Games $607.50 342 4.6 372 SKU-002438
2439 Professional Books Product XL Books $554.03 68 4.5 994 SKU-002439
2440 Premium Office Supplies Product 2024 Office Supplies $989.44 60 3.0 480 SKU-002440
2441 Mega Automotive Product Advanced Automotive $188.10 212 4.9 716 SKU-002441
2442 Mega Clothing Product Max Clothing $603.53 193 2.6 439 SKU-002442
2443 Mega Books Product Plus Books $432.23 21 2.6 887 SKU-002443
2444 Elite Clothing Product Plus Clothing $299.83 327 3.6 441 SKU-002444
2446 Deluxe Health & Beauty Product XL Health & Beauty $548.67 433 4.7 765 SKU-002446
2447 Deluxe Food & Grocery Product Pro Food & Grocery $597.67 183 3.3 0 SKU-002447
2448 Professional Electronics Product Pro Electronics $408.17 329 2.6 65 SKU-002448
2449 Economy Health & Beauty Product Max Health & Beauty $734.50 28 4.6 550 SKU-002449
2450 Mega Food & Grocery Product Pro Food & Grocery $522.26 16 1.6 726 SKU-002450
2451 Mega Toys & Games Product Advanced Toys & Games $118.92 31 2.9 884 SKU-002451
2452 Standard Clothing Product Special Edition Clothing $765.78 123 1.2 508 SKU-002452
2453 Professional Food & Grocery Product Mini Food & Grocery $930.14 217 3.0 90 SKU-002453
2455 Premium Office Supplies Product Mini Office Supplies $77.93 373 3.0 694 SKU-002455
2456 Professional Books Product Special Edition Books $510.53 93 4.9 422 SKU-002456
2457 Pro Food & Grocery Product Lite Food & Grocery $419.20 13 2.4 409 SKU-002457
2458 Pro Clothing Product Advanced Clothing $521.34 452 3.9 248 SKU-002458
2459 Professional Electronics Product Advanced Electronics $466.77 224 3.7 26 SKU-002459
2460 Super Electronics Product Special Edition Electronics $332.94 114 3.4 286 SKU-002460
2461 Pro Books Product Classic Books $724.48 283 2.4 413 SKU-002461
2463 Pro Health & Beauty Product Classic Health & Beauty $136.90 374 4.4 725 SKU-002463
2465 Ultra Food & Grocery Product Classic Food & Grocery $448.85 227 3.4 397 SKU-002465
2466 Standard Books Product Plus Books $941.97 227 3.0 300 SKU-002466
2468 Economy Electronics Product Pro Electronics $777.40 473 1.9 858 SKU-002468
2469 Standard Home & Garden Product Lite Home & Garden $814.77 199 1.9 977 SKU-002469
2470 Economy Food & Grocery Product Plus Food & Grocery $245.26 341 2.2 912 SKU-002470
2472 Ultra Sports & Outdoors Product XL Sports & Outdoors $84.62 494 1.1 658 SKU-002472
2473 Deluxe Sports & Outdoors Product Max Sports & Outdoors $690.22 48 3.2 133 SKU-002473
2474 Deluxe Sports & Outdoors Product Plus Sports & Outdoors $505.37 378 1.2 183 SKU-002474
2475 Elite Electronics Product 2024 Electronics $917.06 101 3.9 940 SKU-002475
2476 Super Home & Garden Product Lite Home & Garden $151.20 44 2.6 206 SKU-002476
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