Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

55 ms

Page Size

25

Current Page

125 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 125 Results Showing 3101 - 3125 of 24441

ID Name Category Price Stock Rating Reviews SKU
3480 Standard Toys & Games Product Lite Toys & Games $843.31 110 3.6 492 SKU-003480
3482 Standard Office Supplies Product 2024 Office Supplies $405.56 5 3.3 420 SKU-003482
3483 Ultra Sports & Outdoors Product Lite Sports & Outdoors $783.62 474 2.2 109 SKU-003483
3484 Mega Health & Beauty Product Pro Health & Beauty $982.01 43 2.6 383 SKU-003484
3485 Premium Sports & Outdoors Product Pro Sports & Outdoors $32.08 124 1.5 687 SKU-003485
3486 Elite Office Supplies Product Lite Office Supplies $108.93 124 1.3 449 SKU-003486
3487 Super Home & Garden Product Special Edition Home & Garden $790.90 83 4.1 794 SKU-003487
3488 Elite Books Product Pro Books $45.71 70 4.8 762 SKU-003488
3490 Economy Office Supplies Product Plus Office Supplies $177.00 143 4.9 798 SKU-003490
3491 Economy Health & Beauty Product Mini Health & Beauty $314.44 285 3.4 751 SKU-003491
3492 Ultra Automotive Product Special Edition Automotive $319.43 496 1.5 437 SKU-003492
3493 Super Food & Grocery Product Special Edition Food & Grocery $199.80 144 2.8 210 SKU-003493
3494 Standard Toys & Games Product Classic Toys & Games $707.06 19 1.6 349 SKU-003494
3495 Elite Sports & Outdoors Product 2024 Sports & Outdoors $26.96 493 1.3 852 SKU-003495
3496 Super Home & Garden Product 2024 Home & Garden $590.14 491 2.3 731 SKU-003496
3497 Professional Home & Garden Product Pro Home & Garden $930.75 262 4.9 16 SKU-003497
3498 Ultra Health & Beauty Product Lite Health & Beauty $307.67 340 3.7 312 SKU-003498
3499 Standard Home & Garden Product XL Home & Garden $765.34 259 2.3 231 SKU-003499
3500 Elite Toys & Games Product Advanced Toys & Games $558.33 428 4.3 227 SKU-003500
3501 Elite Health & Beauty Product XL Health & Beauty $26.45 78 2.3 693 SKU-003501
3503 Premium Sports & Outdoors Product Advanced Sports & Outdoors $185.33 159 3.4 906 SKU-003503
3505 Premium Clothing Product Lite Clothing $65.71 199 3.8 399 SKU-003505
3506 Ultra Clothing Product Mini Clothing $699.15 112 2.6 925 SKU-003506
3507 Mega Food & Grocery Product Special Edition Food & Grocery $937.36 21 1.2 917 SKU-003507
3508 Premium Books Product 2024 Books $955.50 78 2.5 194 SKU-003508
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