Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

9 ms

Page Size

25

Current Page

54 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 54 Results Showing 1326 - 1350 of 24441

ID Name Category Price Stock Rating Reviews SKU
1506 Premium Food & Grocery Product XL Food & Grocery $421.50 404 4.4 215 SKU-001506
1508 Deluxe Sports & Outdoors Product Lite Sports & Outdoors $454.86 444 2.5 228 SKU-001508
1509 Deluxe Toys & Games Product Advanced Toys & Games $724.10 383 4.1 696 SKU-001509
1510 Professional Automotive Product 2024 Automotive $797.29 134 2.1 985 SKU-001510
1511 Economy Automotive Product Advanced Automotive $677.02 322 3.9 518 SKU-001511
1512 Professional Electronics Product Pro Electronics $240.58 87 1.9 252 SKU-001512
1513 Premium Clothing Product Advanced Clothing $130.76 83 2.1 407 SKU-001513
1514 Mega Clothing Product Plus Clothing $828.33 53 1.8 215 SKU-001514
1515 Pro Sports & Outdoors Product Pro Sports & Outdoors $868.12 373 3.9 473 SKU-001515
1517 Elite Clothing Product Pro Clothing $415.24 444 4.9 795 SKU-001517
1518 Mega Electronics Product Lite Electronics $307.44 13 4.1 65 SKU-001518
1519 Super Office Supplies Product Advanced Office Supplies $609.21 443 4.9 71 SKU-001519
1521 Professional Automotive Product Mini Automotive $225.71 141 3.8 838 SKU-001521
1523 Standard Office Supplies Product Classic Office Supplies $314.92 174 1.3 973 SKU-001523
1524 Ultra Automotive Product Max Automotive $865.02 34 4.5 823 SKU-001524
1525 Mega Automotive Product XL Automotive $692.86 3 4.2 628 SKU-001525
1526 Super Food & Grocery Product Advanced Food & Grocery $870.29 92 1.6 594 SKU-001526
1527 Premium Books Product Advanced Books $670.04 310 2.4 327 SKU-001527
1528 Economy Home & Garden Product Mini Home & Garden $569.31 304 2.3 802 SKU-001528
1529 Economy Food & Grocery Product Classic Food & Grocery $953.47 102 1.9 978 SKU-001529
1530 Pro Books Product Pro Books $491.96 262 1.4 450 SKU-001530
1531 Mega Books Product 2024 Books $464.87 25 4.4 94 SKU-001531
1532 Elite Clothing Product Plus Clothing $592.82 159 4.8 22 SKU-001532
1533 Ultra Health & Beauty Product Max Health & Beauty $897.52 425 4.5 603 SKU-001533
1535 Economy Health & Beauty Product Pro Health & Beauty $435.60 328 4.1 614 SKU-001535
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