Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

60 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 60 Results Showing 1476 - 1500 of 24441

ID Name Category Price Stock Rating Reviews SKU
1673 Deluxe Books Product Plus Books $880.31 310 4.5 682 SKU-001673
1675 Professional Automotive Product Special Edition Automotive $299.31 335 2.0 27 SKU-001675
1676 Ultra Electronics Product Max Electronics $103.90 172 4.6 227 SKU-001676
1677 Elite Health & Beauty Product Special Edition Health & Beauty $769.39 401 4.7 365 SKU-001677
1678 Super Automotive Product Pro Automotive $693.03 408 2.6 238 SKU-001678
1679 Ultra Automotive Product Lite Automotive $90.60 108 2.7 709 SKU-001679
1681 Professional Health & Beauty Product Plus Health & Beauty $98.45 26 2.3 777 SKU-001681
1682 Ultra Home & Garden Product Advanced Home & Garden $860.07 104 2.9 517 SKU-001682
1683 Deluxe Food & Grocery Product Special Edition Food & Grocery $767.40 174 1.4 760 SKU-001683
1684 Economy Office Supplies Product XL Office Supplies $909.05 458 1.4 857 SKU-001684
1685 Professional Clothing Product Max Clothing $811.61 280 2.6 675 SKU-001685
1686 Professional Home & Garden Product Plus Home & Garden $906.25 306 4.5 911 SKU-001686
1687 Super Office Supplies Product XL Office Supplies $334.75 88 3.1 607 SKU-001687
1688 Elite Automotive Product Advanced Automotive $627.97 242 3.3 217 SKU-001688
1689 Deluxe Toys & Games Product Classic Toys & Games $268.37 96 4.4 449 SKU-001689
1690 Mega Home & Garden Product Plus Home & Garden $448.97 180 2.5 889 SKU-001690
1691 Elite Health & Beauty Product Plus Health & Beauty $145.34 46 3.8 670 SKU-001691
1693 Super Toys & Games Product Max Toys & Games $391.13 245 1.8 865 SKU-001693
1694 Deluxe Books Product Classic Books $464.01 303 2.8 108 SKU-001694
1695 Deluxe Food & Grocery Product Plus Food & Grocery $61.14 180 1.8 979 SKU-001695
1696 Economy Toys & Games Product Advanced Toys & Games $79.17 236 4.6 627 SKU-001696
1697 Pro Electronics Product Special Edition Electronics $497.12 288 3.7 656 SKU-001697
1698 Standard Toys & Games Product 2024 Toys & Games $136.10 281 2.1 928 SKU-001698
1699 Premium Books Product Pro Books $86.02 49 1.7 291 SKU-001699
1700 Deluxe Health & Beauty Product Classic Health & Beauty $981.85 72 1.4 882 SKU-001700
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