Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

39 ms

Page Size

25

Current Page

823 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 823 Results Showing 20551 - 20575 of 24441

ID Name Category Price Stock Rating Reviews SKU
21110 Bulk Product f1879e38 Clothing $28.66 343 3.7 87 BULK-573022a4
21111 Bulk Product 62cf194b Books $150.52 476 0.9 7 BULK-71e6016b
21112 Bulk Product efbe3a9e Toys & Games $974.02 128 2.0 60 BULK-8a3a8e32
21113 Bulk Product 0cd86a74 Electronics $739.13 266 1.1 73 BULK-5ae66d87
21114 Bulk Product 13707cb1 Home & Garden $654.26 134 4.3 95 BULK-a1ce315f
21115 Bulk Product 9c840b03 Home & Garden $32.97 44 0.6 45 BULK-9574f866
21116 Bulk Product d2e39784 Clothing $464.91 153 4.5 6 BULK-554a126e
21117 Bulk Product 81ad7081 Sports & Outdoors $460.62 245 1.5 8 BULK-2ffb243d
21118 Bulk Product 9ea748f2 Toys & Games $48.42 179 2.9 79 BULK-38a19064
21119 Bulk Product 16b33d76 Books $521.67 109 2.2 22 BULK-d3a1a5c2
21120 Bulk Product eccfafbd Electronics $854.37 96 0.7 26 BULK-f19dcd6f
21121 Bulk Product 4325df06 Home & Garden $902.83 70 0.2 21 BULK-b6586eb8
21122 Bulk Product 305a328d Home & Garden $70.21 210 2.6 83 BULK-928b2284
21123 Bulk Product 4fbb6583 Clothing $372.31 288 2.6 75 BULK-a597210c
21124 Bulk Product 9d6993a2 Electronics $672.36 446 4.8 86 BULK-3dc44462
21125 Bulk Product 0ad9e9d5 Toys & Games $592.03 422 4.7 17 BULK-83ecb9bc
21126 Bulk Product 564c9648 Home & Garden $936.48 352 4.1 58 BULK-594a5b28
21127 Bulk Product 28e7cffb Clothing $550.53 430 1.5 34 BULK-1e4520a3
21128 Bulk Product 7a67d2dd Toys & Games $673.14 323 4.2 55 BULK-3329697a
21129 Bulk Product f87f950c Home & Garden $605.25 375 3.3 59 BULK-ebcc99e6
21130 Bulk Product 413781fa Sports & Outdoors $949.52 487 0.5 70 BULK-a7beaf91
21131 Bulk Product 4fd4c1f1 Toys & Games $311.90 228 1.5 54 BULK-2f786257
21132 Bulk Product e20d4681 Books $549.68 205 4.8 15 BULK-bfed7a95
21133 Bulk Product afba026a Clothing $964.34 48 3.1 95 BULK-c936f63c
21134 Bulk Product 328e86fb Books $890.64 87 2.6 33 BULK-a218354b
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