Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

27 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 27 Results Showing 651 - 675 of 24441

ID Name Category Price Stock Rating Reviews SKU
727 Deluxe Toys & Games Product Mini Toys & Games $422.17 41 1.4 392 SKU-000727
729 Economy Books Product 2024 Books $799.51 363 1.4 858 SKU-000729
730 Standard Food & Grocery Product Mini Food & Grocery $88.06 276 4.5 14 SKU-000730
731 Premium Food & Grocery Product Max Food & Grocery $239.27 168 2.0 234 SKU-000731
732 Economy Home & Garden Product 2024 Home & Garden $328.53 104 4.1 509 SKU-000732
733 Pro Health & Beauty Product XL Health & Beauty $77.74 209 4.4 283 SKU-000733
734 Pro Food & Grocery Product Mini Food & Grocery $856.73 175 4.6 34 SKU-000734
735 Super Electronics Product Special Edition Electronics $899.40 432 3.4 535 SKU-000735
736 Ultra Clothing Product Lite Clothing $621.71 177 4.7 191 SKU-000736
737 Mega Office Supplies Product Advanced Office Supplies $650.13 169 1.9 950 SKU-000737
738 Pro Electronics Product Mini Electronics $164.42 389 4.4 243 SKU-000738
739 Standard Books Product Classic Books $101.76 365 4.8 574 SKU-000739
741 Elite Toys & Games Product XL Toys & Games $314.85 382 4.4 637 SKU-000741
743 Economy Food & Grocery Product Max Food & Grocery $174.03 21 1.1 300 SKU-000743
744 Standard Automotive Product Pro Automotive $897.17 62 1.2 488 SKU-000744
745 Professional Books Product Pro Books $951.08 248 1.2 932 SKU-000745
746 Premium Electronics Product Mini Electronics $187.07 122 2.8 234 SKU-000746
747 Mega Health & Beauty Product Advanced Health & Beauty $965.03 268 4.9 677 SKU-000747
748 Deluxe Office Supplies Product Classic Office Supplies $764.80 499 1.1 49 SKU-000748
749 Professional Automotive Product Plus Automotive $235.66 43 1.9 385 SKU-000749
750 Mega Clothing Product Special Edition Clothing $649.42 437 4.2 225 SKU-000750
751 Professional Health & Beauty Product Special Edition Health & Beauty $36.61 405 4.6 970 SKU-000751
752 Deluxe Books Product Plus Books $911.02 341 4.8 934 SKU-000752
753 Mega Health & Beauty Product Plus Health & Beauty $224.12 5 2.9 863 SKU-000753
754 Pro Electronics Product Special Edition Electronics $384.02 95 1.0 147 SKU-000754
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