Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

57 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 57 Results Showing 1401 - 1425 of 24441

ID Name Category Price Stock Rating Reviews SKU
1591 Professional Electronics Product Classic Electronics $314.21 367 3.6 639 SKU-001591
1592 Elite Books Product Pro Books $86.76 148 4.4 828 SKU-001592
1593 Super Sports & Outdoors Product Special Edition Sports & Outdoors $938.66 460 2.0 102 SKU-001593
1594 Economy Electronics Product Special Edition Electronics $572.30 94 4.9 616 SKU-001594
1595 Pro Electronics Product Mini Electronics $99.50 15 5.0 160 SKU-001595
1596 Ultra Health & Beauty Product Mini Health & Beauty $639.09 56 4.5 684 SKU-001596
1597 Economy Home & Garden Product Advanced Home & Garden $979.91 441 2.9 90 SKU-001597
1598 Premium Health & Beauty Product Mini Health & Beauty $785.69 73 1.4 377 SKU-001598
1599 Professional Electronics Product Classic Electronics $992.66 37 3.7 100 SKU-001599
1601 Standard Toys & Games Product Classic Toys & Games $214.65 353 2.1 641 SKU-001601
1602 Economy Toys & Games Product Advanced Toys & Games $706.45 150 2.4 381 SKU-001602
1603 Super Automotive Product Lite Automotive $156.29 440 1.2 706 SKU-001603
1605 Standard Food & Grocery Product Plus Food & Grocery $710.01 322 3.1 65 SKU-001605
1606 Premium Automotive Product Max Automotive $638.05 90 2.9 523 SKU-001606
1607 Pro Office Supplies Product Plus Office Supplies $717.60 41 2.5 876 SKU-001607
1608 Economy Automotive Product Max Automotive $84.06 329 1.5 672 SKU-001608
1609 Super Clothing Product Lite Clothing $518.98 78 2.2 49 SKU-001609
1610 Mega Books Product Special Edition Books $63.80 361 3.4 297 SKU-001610
1611 Ultra Home & Garden Product Classic Home & Garden $360.93 489 2.2 530 SKU-001611
1612 Pro Home & Garden Product Max Home & Garden $762.61 110 3.8 943 SKU-001612
1613 Mega Home & Garden Product Mini Home & Garden $838.96 186 4.0 333 SKU-001613
1614 Standard Books Product Max Books $551.45 422 2.9 172 SKU-001614
1615 Professional Electronics Product 2024 Electronics $217.56 430 2.9 63 SKU-001615
1616 Pro Books Product Advanced Books $651.50 142 3.8 263 SKU-001616
1617 Mega Food & Grocery Product Classic Food & Grocery $669.08 159 2.6 722 SKU-001617
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