Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

58 ms

Page Size

25

Current Page

272 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 272 Results Showing 6776 - 6800 of 24441

ID Name Category Price Stock Rating Reviews SKU
7335 Bulk Product c119cb3b Home & Garden $777.49 93 2.3 58 BULK-e735536b
7336 Bulk Product 1dc3d2fa Clothing $293.23 331 2.6 92 BULK-bea780ec
7337 Bulk Product c2f11531 Sports & Outdoors $314.51 22 3.2 13 BULK-56eb3a4c
7338 Bulk Product 4b424943 Sports & Outdoors $141.03 498 3.3 7 BULK-db5028ce
7339 Bulk Product d8db0754 Electronics $20.60 40 2.3 81 BULK-3f8ec40c
7340 Bulk Product f396e226 Home & Garden $222.34 23 0.4 35 BULK-8709a50a
7341 Bulk Product cf7c6fa9 Toys & Games $172.11 188 1.9 73 BULK-dc61d557
7342 Bulk Product 4d11001c Toys & Games $206.99 72 1.0 68 BULK-7fc60403
7343 Bulk Product 04eb7258 Sports & Outdoors $365.95 79 4.3 80 BULK-4958e8d0
7344 Bulk Product b7de100a Books $983.06 345 4.1 74 BULK-cfd0a86e
7345 Bulk Product adc73238 Electronics $889.74 181 0.0 65 BULK-7fc1a528
7346 Bulk Product 72ba5fe2 Clothing $730.22 269 3.5 96 BULK-606984f9
7347 Bulk Product c1ca0b0f Home & Garden $424.09 458 1.7 43 BULK-e327c730
7348 Bulk Product e0f8ccf7 Sports & Outdoors $804.80 463 0.1 12 BULK-52d627c2
7349 Bulk Product f9db29e9 Toys & Games $96.16 350 4.1 8 BULK-d2774cbb
7350 Bulk Product e004e649 Toys & Games $189.30 133 0.9 81 BULK-d74ee444
7351 Bulk Product e4c7c8af Sports & Outdoors $739.88 30 4.8 70 BULK-2844f222
7352 Bulk Product 45de8164 Toys & Games $855.36 3 3.2 13 BULK-28425aa5
7353 Bulk Product f984406c Sports & Outdoors $246.20 38 0.3 37 BULK-950a73a9
7354 Bulk Product e32778c7 Clothing $631.04 49 1.9 18 BULK-1c13c4ae
7355 Bulk Product cc626332 Toys & Games $284.33 118 3.9 21 BULK-7b2c616d
7356 Bulk Product 77f7420a Electronics $659.29 318 3.0 51 BULK-83394179
7357 Bulk Product c8f96c2b Electronics $760.53 276 2.4 15 BULK-86abc6be
7358 Bulk Product 3cd4097d Sports & Outdoors $374.13 119 1.1 21 BULK-310534e9
7359 Bulk Product badb5e54 Toys & Games $931.94 35 4.8 92 BULK-55d152b0
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