Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

51 ms

Page Size

25

Current Page

59 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 59 Results Showing 1451 - 1475 of 24441

ID Name Category Price Stock Rating Reviews SKU
1645 Deluxe Clothing Product XL Clothing $416.91 383 4.1 529 SKU-001645
1646 Premium Sports & Outdoors Product Lite Sports & Outdoors $834.17 113 3.8 430 SKU-001646
1647 Pro Health & Beauty Product Pro Health & Beauty $789.84 188 2.1 207 SKU-001647
1648 Elite Food & Grocery Product Advanced Food & Grocery $517.66 159 4.2 842 SKU-001648
1649 Ultra Toys & Games Product 2024 Toys & Games $666.52 12 3.0 329 SKU-001649
1650 Economy Automotive Product Classic Automotive $533.68 233 2.1 240 SKU-001650
1651 Professional Sports & Outdoors Product Advanced Sports & Outdoors $132.33 319 2.1 514 SKU-001651
1652 Pro Clothing Product Pro Clothing $427.22 219 1.2 583 SKU-001652
1654 Premium Office Supplies Product Max Office Supplies $381.87 258 4.6 735 SKU-001654
1655 Mega Home & Garden Product Mini Home & Garden $853.53 268 4.8 374 SKU-001655
1657 Pro Books Product Special Edition Books $948.84 166 4.2 131 SKU-001657
1658 Economy Electronics Product XL Electronics $803.11 348 1.9 114 SKU-001658
1659 Ultra Electronics Product Lite Electronics $675.29 433 1.1 549 SKU-001659
1660 Deluxe Books Product Pro Books $693.17 16 2.9 152 SKU-001660
1661 Professional Toys & Games Product Plus Toys & Games $860.47 50 2.7 863 SKU-001661
1662 Economy Health & Beauty Product Pro Health & Beauty $208.75 294 2.4 52 SKU-001662
1663 Ultra Health & Beauty Product Lite Health & Beauty $133.53 343 3.9 813 SKU-001663
1664 Mega Books Product Max Books $188.64 400 2.3 404 SKU-001664
1665 Premium Electronics Product XL Electronics $437.14 265 4.4 164 SKU-001665
1666 Ultra Electronics Product Classic Electronics $768.32 415 1.5 549 SKU-001666
1668 Mega Food & Grocery Product Lite Food & Grocery $302.98 48 3.5 125 SKU-001668
1669 Ultra Books Product 2024 Books $460.63 432 1.4 709 SKU-001669
1670 Pro Clothing Product Plus Clothing $544.89 255 3.5 557 SKU-001670
1671 Ultra Toys & Games Product Pro Toys & Games $697.86 23 1.5 271 SKU-001671
1672 Professional Health & Beauty Product Max Health & Beauty $828.21 461 3.3 924 SKU-001672
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