Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

122 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 122 Results Showing 3026 - 3050 of 24441

ID Name Category Price Stock Rating Reviews SKU
3395 Super Clothing Product Max Clothing $969.81 24 3.8 38 SKU-003395
3396 Elite Toys & Games Product 2024 Toys & Games $394.20 327 2.5 458 SKU-003396
3397 Pro Office Supplies Product Plus Office Supplies $987.04 459 3.2 722 SKU-003397
3398 Mega Office Supplies Product Plus Office Supplies $584.67 488 3.7 702 SKU-003398
3399 Ultra Electronics Product Max Electronics $307.91 387 4.5 719 SKU-003399
3400 Premium Toys & Games Product Plus Toys & Games $709.27 144 3.7 653 SKU-003400
3401 Elite Office Supplies Product Special Edition Office Supplies $148.44 311 1.2 990 SKU-003401
3404 Ultra Toys & Games Product Max Toys & Games $138.07 109 4.4 220 SKU-003404
3406 Pro Home & Garden Product XL Home & Garden $124.96 442 1.1 51 SKU-003406
3407 Mega Toys & Games Product Advanced Toys & Games $257.79 437 4.3 943 SKU-003407
3410 Deluxe Electronics Product Advanced Electronics $17.73 246 4.8 836 SKU-003410
3411 Pro Food & Grocery Product Pro Food & Grocery $218.35 190 3.1 162 SKU-003411
3412 Ultra Health & Beauty Product Special Edition Health & Beauty $868.72 70 2.5 239 SKU-003412
3413 Mega Health & Beauty Product Special Edition Health & Beauty $823.92 349 3.7 14 SKU-003413
3414 Elite Electronics Product 2024 Electronics $139.59 62 4.0 971 SKU-003414
3415 Standard Sports & Outdoors Product Pro Sports & Outdoors $71.98 322 1.8 115 SKU-003415
3416 Economy Health & Beauty Product Max Health & Beauty $670.45 438 3.1 351 SKU-003416
3417 Ultra Clothing Product Pro Clothing $674.28 481 3.6 178 SKU-003417
3418 Ultra Electronics Product Plus Electronics $718.30 332 3.0 527 SKU-003418
3419 Professional Automotive Product Classic Automotive $744.41 138 3.1 129 SKU-003419
3420 Premium Office Supplies Product Special Edition Office Supplies $256.74 87 2.5 743 SKU-003420
3421 Premium Food & Grocery Product 2024 Food & Grocery $61.62 82 4.1 710 SKU-003421
3422 Super Automotive Product XL Automotive $547.50 376 2.2 576 SKU-003422
3423 Premium Automotive Product Max Automotive $276.13 135 4.7 339 SKU-003423
3425 Economy Sports & Outdoors Product Plus Sports & Outdoors $91.31 487 1.9 381 SKU-003425
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