Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

1634 ms

Page Size

25

Current Page

834 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 834 Results Showing 20826 - 20850 of 24441

ID Name Category Price Stock Rating Reviews SKU
21385 Bulk Product 5ccd14ea Toys & Games $157.25 203 0.5 38 BULK-6bcbc517
21386 Bulk Product cc8e7463 Electronics $83.99 284 1.1 54 BULK-aa1a208d
21387 Bulk Product 3261dbc2 Sports & Outdoors $119.29 265 0.7 18 BULK-698723a0
21388 Bulk Product 94d0dd85 Sports & Outdoors $965.38 37 2.4 98 BULK-d1b48a6d
21389 Bulk Product 0e1a957b Toys & Games $470.17 465 3.9 14 BULK-0abdb15a
21390 Bulk Product 0033482b Toys & Games $655.11 132 0.8 15 BULK-8d6bd75c
21391 Bulk Product 2a107804 Home & Garden $387.64 414 4.8 31 BULK-8338dcc0
21392 Bulk Product b7b6154a Books $933.39 69 1.7 71 BULK-138c2622
21393 Bulk Product 93a34d29 Books $915.73 84 0.6 83 BULK-63c056b5
21394 Bulk Product daa0d4fb Home & Garden $941.24 191 4.1 12 BULK-9451d21d
21395 Bulk Product ac004302 Sports & Outdoors $964.40 105 3.4 61 BULK-41e85119
21396 Bulk Product 1358ef11 Sports & Outdoors $718.07 8 1.8 18 BULK-a9161d79
21397 Bulk Product b022d7fb Books $326.63 488 4.0 0 BULK-4fb327b2
21398 Bulk Product 6cd02b55 Sports & Outdoors $64.02 119 2.2 45 BULK-209b9d54
21399 Bulk Product 3cffbdc5 Home & Garden $896.40 265 3.4 20 BULK-dee61fb4
21400 Bulk Product 18371cdd Home & Garden $72.77 223 2.1 95 BULK-3e6aae73
21401 Bulk Product 7379ce22 Clothing $462.91 43 0.2 6 BULK-e184c54a
21402 Bulk Product 21266e90 Toys & Games $430.56 69 0.5 80 BULK-9b621686
21403 Bulk Product 41051bdc Electronics $77.01 41 4.9 41 BULK-d6012d89
21404 Bulk Product 29c73424 Electronics $66.20 206 0.7 78 BULK-7fad0d1b
21405 Bulk Product 40fccbc2 Electronics $92.55 67 2.3 36 BULK-0b900e9d
21406 Bulk Product bc3df27c Clothing $89.60 345 0.0 6 BULK-fcc3abb1
21407 Bulk Product 7a1685f7 Clothing $399.58 487 0.7 8 BULK-91c1d2d6
21408 Bulk Product b544e7bf Home & Garden $111.78 213 2.3 97 BULK-935aa240
21409 Bulk Product f66cc804 Toys & Games $971.06 211 0.2 62 BULK-42e075dc
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