Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

442 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 442 Results Showing 11026 - 11050 of 24441

ID Name Category Price Stock Rating Reviews SKU
11585 Bulk Product 8f5b3a49 Sports & Outdoors $684.70 155 3.9 35 BULK-1582b8d4
11586 Bulk Product fd1c2d44 Clothing $778.88 404 3.3 19 BULK-774c972c
11587 Bulk Product 39d1d0dd Sports & Outdoors $597.49 12 2.3 57 BULK-7bc5c9a5
11588 Bulk Product f907bd98 Home & Garden $865.24 377 0.0 25 BULK-baf26ccf
11589 Bulk Product 63406ae5 Books $171.26 373 1.1 55 BULK-64611f96
11590 Bulk Product ec3c6809 Home & Garden $12.49 207 1.9 52 BULK-0443e7fe
11591 Bulk Product c6e2a984 Electronics $208.59 375 3.2 39 BULK-e1a49b50
11592 Bulk Product e6ac0ffc Books $50.64 495 3.0 94 BULK-f37f5e78
11593 Bulk Product 76e6833c Books $768.89 73 3.7 83 BULK-2cb3e375
11594 Bulk Product 261f8925 Toys & Games $575.34 162 3.2 47 BULK-60d0e8dc
11595 Bulk Product 488d9dba Clothing $228.31 329 0.9 57 BULK-84e0785f
11596 Bulk Product 57b9824a Books $799.62 314 4.0 0 BULK-0ba37896
11597 Bulk Product 0dfb65c7 Toys & Games $465.58 219 4.2 87 BULK-0775b740
11598 Bulk Product 8b474259 Sports & Outdoors $283.21 173 2.1 22 BULK-f608c0c9
11599 Bulk Product 898d387d Toys & Games $650.49 217 1.4 29 BULK-9bf4f2fb
11600 Bulk Product 806280a8 Books $172.30 118 4.6 82 BULK-d74b93ef
11601 Bulk Product 2a3c3322 Toys & Games $94.69 386 1.9 84 BULK-190353e4
11602 Bulk Product 681ae667 Books $832.72 131 1.2 57 BULK-b52ed385
11603 Bulk Product ce93dfe8 Sports & Outdoors $468.57 324 0.9 26 BULK-082c6608
11604 Bulk Product fe996e50 Sports & Outdoors $957.83 312 0.5 18 BULK-78401666
11605 Bulk Product 5911d988 Home & Garden $901.52 283 0.5 72 BULK-ff7ba3a1
11606 Bulk Product 1a92d3a6 Sports & Outdoors $489.61 67 3.9 65 BULK-ae00415d
11607 Bulk Product 595388f3 Toys & Games $453.38 251 1.5 63 BULK-dea08361
11608 Bulk Product 69c82eae Clothing $861.59 266 3.3 72 BULK-e1072cba
11609 Bulk Product c7cfdeb3 Toys & Games $462.60 9 4.4 22 BULK-98180522
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