Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

429 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 429 Results Showing 10701 - 10725 of 24441

ID Name Category Price Stock Rating Reviews SKU
11260 Bulk Product 091a8d30 Books $119.61 128 4.0 90 BULK-5591bef2
11261 Bulk Product 9aae7701 Books $747.79 294 0.4 29 BULK-31ac6bd7
11262 Bulk Product 9623f77c Books $660.92 69 1.3 48 BULK-9c0bcb6c
11263 Bulk Product d624c7b0 Books $298.01 160 0.8 97 BULK-f4eb1733
11264 Bulk Product 99707142 Clothing $360.48 361 0.2 90 BULK-291b97b5
11265 Bulk Product 22fc9b53 Clothing $229.37 397 2.5 57 BULK-b5db0de3
11266 Bulk Product 379951ac Toys & Games $639.05 481 4.6 51 BULK-e36e4e49
11267 Bulk Product 0f604b11 Home & Garden $894.31 65 4.2 98 BULK-b30c6fd4
11268 Bulk Product a692985d Home & Garden $569.10 342 0.8 88 BULK-e15e88c9
11269 Bulk Product c73778e0 Home & Garden $264.13 155 4.6 93 BULK-32ab552b
11270 Bulk Product 08f95aa1 Home & Garden $948.13 272 1.5 29 BULK-7a58f9d6
11271 Bulk Product a1707a66 Toys & Games $155.18 352 2.6 47 BULK-16b5ed70
11272 Bulk Product e9bf68f8 Toys & Games $340.93 219 0.8 8 BULK-e10d8965
11273 Bulk Product 62869a5e Toys & Games $867.04 312 3.1 71 BULK-53d4bf36
11274 Bulk Product 86d41bbd Books $987.73 37 2.6 8 BULK-40a78bad
11275 Bulk Product e5ea2884 Sports & Outdoors $204.81 482 0.8 0 BULK-57e59e23
11276 Bulk Product 9d1a508e Electronics $814.26 361 2.7 52 BULK-e581b7b8
11277 Bulk Product 3e5b8214 Electronics $283.28 320 0.8 3 BULK-5bd7f61b
11278 Bulk Product 2efe1d3a Toys & Games $741.87 423 4.6 57 BULK-d683a876
11279 Bulk Product 385991f1 Clothing $935.49 27 4.3 78 BULK-fa503e45
11280 Bulk Product 040c2efe Electronics $608.81 493 1.6 33 BULK-d74dd5a0
11281 Bulk Product 13120799 Books $286.27 119 4.3 2 BULK-98c69fa8
11282 Bulk Product 10734b2a Books $552.90 483 4.6 70 BULK-4fab269b
11283 Bulk Product eb5f56be Home & Garden $719.11 391 3.6 77 BULK-831a9bb9
11284 Bulk Product eac3bf6f Home & Garden $287.69 413 2.0 80 BULK-8c1f5cb4
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