Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

17 ms

Page Size

25

Current Page

733 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 733 Results Showing 18301 - 18325 of 24441

ID Name Category Price Stock Rating Reviews SKU
18860 Bulk Product e6791154 Toys & Games $217.02 123 4.4 96 BULK-a66c1bc0
18861 Bulk Product deb7f05c Home & Garden $664.69 126 2.9 9 BULK-f5c0f5e4
18862 Bulk Product 48b08953 Home & Garden $244.26 342 3.9 3 BULK-aace4b78
18863 Bulk Product 63ee3826 Books $349.94 75 3.1 29 BULK-d21abf75
18864 Bulk Product 980059ac Sports & Outdoors $211.52 138 4.4 1 BULK-a561a1c1
18865 Bulk Product e25e76c6 Sports & Outdoors $68.61 300 1.8 51 BULK-ff901406
18866 Bulk Product 177c36ed Home & Garden $380.79 243 3.5 43 BULK-f485bff3
18867 Bulk Product d6939471 Clothing $882.32 236 0.3 41 BULK-39e75ed4
18868 Bulk Product c58d3720 Clothing $383.71 393 4.3 80 BULK-43972458
18869 Bulk Product 7493404e Sports & Outdoors $13.39 392 2.0 8 BULK-6c958ba0
18870 Bulk Product e8231807 Electronics $443.09 9 0.2 82 BULK-de40f933
18871 Bulk Product 592763f3 Toys & Games $522.60 239 2.4 36 BULK-2246c470
18872 Bulk Product 451dc106 Clothing $511.70 146 3.6 53 BULK-6e346f9b
18873 Bulk Product 192fd329 Toys & Games $566.16 398 2.0 20 BULK-d7aeebce
18874 Bulk Product 0e9c38ce Books $660.82 478 4.2 68 BULK-b21f3b60
18875 Bulk Product 0df6965e Toys & Games $277.86 301 4.4 16 BULK-2f514bba
18876 Bulk Product be72b8f7 Sports & Outdoors $39.52 125 3.1 70 BULK-c9835a5a
18877 Bulk Product b20c3d70 Clothing $706.34 447 1.2 46 BULK-6f2723c2
18878 Bulk Product 96cfccc2 Books $155.33 372 0.6 42 BULK-d97aaeb2
18879 Bulk Product 4a628068 Electronics $1,002.34 464 0.5 41 BULK-feccd558
18880 Bulk Product 63e01aad Sports & Outdoors $607.72 353 2.6 26 BULK-ebce1737
18881 Bulk Product c484fe2f Sports & Outdoors $271.63 340 2.0 2 BULK-c80c1e50
18882 Bulk Product 5f513750 Electronics $322.15 244 0.3 98 BULK-448c4899
18883 Bulk Product 1807bc8e Electronics $438.90 362 3.0 50 BULK-351320f7
18884 Bulk Product fe486d9e Clothing $341.08 258 2.9 29 BULK-f9f370d3
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