Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

29 ms

Page Size

25

Current Page

638 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 638 Results Showing 15926 - 15950 of 24441

ID Name Category Price Stock Rating Reviews SKU
16485 Bulk Product 53ac324e Books $283.88 308 1.2 74 BULK-7275d412
16486 Bulk Product 59968ae8 Books $583.38 142 1.3 56 BULK-6c8d1b58
16487 Bulk Product 037f4d08 Home & Garden $710.20 365 2.4 88 BULK-283469ac
16488 Bulk Product 10874004 Toys & Games $734.51 38 1.8 44 BULK-465dc2cf
16489 Bulk Product fe53b3cb Sports & Outdoors $230.02 329 0.2 81 BULK-f90cc28c
16490 Bulk Product 2be96a4d Home & Garden $380.10 493 2.2 17 BULK-28b4071f
16491 Bulk Product 030c14e0 Clothing $428.57 177 2.1 75 BULK-90e46bf8
16492 Bulk Product 1509079f Electronics $699.95 416 3.5 96 BULK-d8a51138
16493 Bulk Product f47f452b Sports & Outdoors $862.92 220 3.8 61 BULK-c9ac3ae5
16494 Bulk Product eb068ab7 Home & Garden $835.05 152 1.4 82 BULK-11217f92
16495 Bulk Product d7c7cf0f Electronics $397.33 316 3.8 51 BULK-b56e387b
16496 Bulk Product 79b62db8 Books $991.09 237 0.6 92 BULK-74a71da3
16497 Bulk Product 04af5401 Electronics $426.84 445 1.9 18 BULK-da25b235
16498 Bulk Product 58442175 Electronics $137.29 379 1.8 92 BULK-d69bc488
16499 Bulk Product 15ca765e Books $119.54 205 0.9 14 BULK-a46153f6
16500 Bulk Product f6acffb2 Home & Garden $102.03 168 0.1 40 BULK-5cd96712
16501 Bulk Product ee74f57d Electronics $604.25 359 4.8 69 BULK-72665f77
16502 Bulk Product a7ffe838 Home & Garden $798.27 469 1.5 21 BULK-ce1340ba
16503 Bulk Product 929b4651 Home & Garden $245.41 21 2.1 97 BULK-dac5706b
16504 Bulk Product ef91edc3 Clothing $662.12 156 0.9 47 BULK-39cfc2e1
16505 Bulk Product 3a076200 Toys & Games $635.78 227 2.3 69 BULK-91013709
16506 Bulk Product da1c0344 Toys & Games $101.61 211 2.0 39 BULK-829004e2
16507 Bulk Product 2eff4dce Books $974.84 72 4.7 69 BULK-377a49b2
16508 Bulk Product fc8690a7 Toys & Games $680.04 494 0.8 46 BULK-bb344214
16509 Bulk Product db804033 Clothing $512.04 70 2.4 56 BULK-f50a1e0d
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