Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

65 ms

Page Size

25

Current Page

672 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 672 Results Showing 16776 - 16800 of 24441

ID Name Category Price Stock Rating Reviews SKU
17335 Bulk Product 52235005 Books $903.45 308 1.4 9 BULK-025c783a
17336 Bulk Product 54b6b198 Toys & Games $990.60 112 2.8 67 BULK-1d15c363
17337 Bulk Product e2e78064 Home & Garden $795.27 251 2.4 9 BULK-ba2c7e1f
17338 Bulk Product 39c5e34b Home & Garden $16.83 484 2.2 0 BULK-67b111fb
17339 Bulk Product fc99f5c0 Toys & Games $926.02 217 4.5 3 BULK-6a626e3a
17340 Bulk Product 716c7a80 Sports & Outdoors $869.67 155 1.7 57 BULK-877ae13a
17341 Bulk Product 7909c6a2 Clothing $677.99 99 3.6 51 BULK-b3a0d601
17342 Bulk Product 34f86a72 Sports & Outdoors $694.36 98 3.7 11 BULK-0b92b38d
17343 Bulk Product f5bb21a9 Electronics $490.47 441 2.6 86 BULK-4b22d0e8
17344 Bulk Product 526726d0 Clothing $550.80 89 2.6 81 BULK-55bb9444
17345 Bulk Product 8d30b6ed Sports & Outdoors $324.86 456 2.8 3 BULK-2d7f1a0f
17346 Bulk Product 41e8c2ec Toys & Games $930.58 5 0.8 95 BULK-dd9fa9d3
17347 Bulk Product 590fa134 Sports & Outdoors $805.11 298 0.4 74 BULK-17995671
17348 Bulk Product 8bd29a47 Sports & Outdoors $145.08 56 2.0 76 BULK-0161a116
17349 Bulk Product 5ed9356a Clothing $926.50 354 2.2 26 BULK-56ed4e70
17350 Bulk Product 51f32ba9 Books $10.24 40 1.3 46 BULK-84e5de2f
17351 Bulk Product c78738d8 Clothing $419.53 350 2.6 4 BULK-c1375d54
17352 Bulk Product 0733e26b Toys & Games $403.68 434 0.7 86 BULK-4ef401e2
17353 Bulk Product 319bd00d Books $75.92 429 0.1 19 BULK-04731b6c
17354 Bulk Product 7db9006c Home & Garden $195.42 441 0.8 18 BULK-a7766023
17355 Bulk Product 614d2577 Toys & Games $229.11 125 0.0 50 BULK-bab9cbb8
17356 Bulk Product c2bc4171 Toys & Games $963.16 158 0.6 70 BULK-13a1e1bd
17357 Bulk Product 73d56a33 Clothing $167.28 59 3.0 89 BULK-f8e307b2
17358 Bulk Product 0d96e829 Books $621.70 57 4.8 71 BULK-d3a9a2e1
17359 Bulk Product 2f969cb1 Toys & Games $19.27 49 0.4 4 BULK-34856d6e
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