Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

402 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 402 Results Showing 10026 - 10050 of 24441

ID Name Category Price Stock Rating Reviews SKU
10585 Bulk Product 91933a8b Sports & Outdoors $701.97 407 4.9 38 BULK-2630e088
10586 Bulk Product 39c2fcb1 Sports & Outdoors $98.98 292 2.1 30 BULK-a99bed74
10587 Bulk Product d318bdd0 Books $966.43 26 0.7 69 BULK-95b42966
10588 Bulk Product 70d64e3a Home & Garden $136.40 308 1.8 9 BULK-1c9ca312
10589 Bulk Product 199074f9 Clothing $316.87 191 4.3 19 BULK-965e9573
10590 Bulk Product bf54e81d Sports & Outdoors $649.99 179 1.1 7 BULK-ee598631
10591 Bulk Product 103ab6f6 Home & Garden $367.22 209 3.8 13 BULK-292f5809
10592 Bulk Product dd9ed3dd Books $640.84 427 3.3 78 BULK-0579fa3d
10593 Bulk Product 8c1cf77f Clothing $655.11 142 0.5 52 BULK-5037c083
10594 Bulk Product 81ed9328 Toys & Games $446.29 447 2.3 0 BULK-d73b3d12
10595 Bulk Product 2e80ec78 Sports & Outdoors $506.54 478 0.2 84 BULK-e26bbeac
10596 Bulk Product b5d794bb Electronics $433.23 374 0.5 30 BULK-5cc03fdf
10597 Bulk Product dda3a411 Clothing $232.82 422 2.1 66 BULK-886355dd
10598 Bulk Product dc2fc0f3 Electronics $418.39 233 2.9 2 BULK-cf1fd1fe
10599 Bulk Product bb17b9d8 Electronics $760.48 28 1.4 6 BULK-b6ea2f56
10600 Bulk Product 2c392ff6 Clothing $439.31 293 1.5 43 BULK-b86cbb81
10601 Bulk Product 31eab6d0 Sports & Outdoors $424.74 498 1.8 57 BULK-ed017d3c
10602 Bulk Product a1fe5b67 Toys & Games $466.89 269 4.0 40 BULK-e51ea144
10603 Bulk Product e16df839 Books $325.66 434 2.4 38 BULK-183f606c
10604 Bulk Product f81e41ba Electronics $525.18 338 3.5 91 BULK-98425180
10605 Bulk Product e9f1695a Sports & Outdoors $655.12 413 0.2 85 BULK-51f1f80a
10606 Bulk Product 28958d4c Sports & Outdoors $93.40 159 2.2 99 BULK-f43c67ab
10607 Bulk Product cdc40404 Books $829.10 199 1.5 61 BULK-9ae3ac81
10608 Bulk Product 83437562 Sports & Outdoors $450.95 65 0.3 25 BULK-a35afcc1
10609 Bulk Product 36e1b325 Clothing $766.76 244 4.2 67 BULK-f4127e45
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