Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

560 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 560 Results Showing 13976 - 14000 of 24441

ID Name Category Price Stock Rating Reviews SKU
14535 Bulk Product 28e5cfbb Electronics $761.68 120 1.2 49 BULK-453302d3
14536 Bulk Product 88de92cf Toys & Games $350.37 449 2.5 48 BULK-86996a6e
14537 Bulk Product 36586dd4 Clothing $40.28 393 4.1 73 BULK-36e01e5c
14538 Bulk Product f6c544bf Books $891.93 491 3.5 99 BULK-aec45863
14539 Bulk Product f5aeecf3 Home & Garden $407.45 371 2.3 86 BULK-e1990d7d
14540 Bulk Product 034d94e1 Toys & Games $931.00 492 0.1 38 BULK-7fd235e7
14541 Bulk Product 2f0e8ce9 Electronics $844.89 393 1.8 50 BULK-61a74b8c
14542 Bulk Product 958159b9 Books $852.63 472 4.6 40 BULK-c949c134
14543 Bulk Product 35494b8b Books $646.68 464 0.7 77 BULK-97455df5
14544 Bulk Product f0b97144 Toys & Games $636.28 142 2.7 35 BULK-5ae73f9b
14545 Bulk Product bdecbe54 Clothing $511.44 108 3.1 62 BULK-23775c1d
14546 Bulk Product f13a9d95 Toys & Games $906.54 37 3.0 44 BULK-fe468703
14547 Bulk Product 387bd4e5 Clothing $863.48 50 2.3 25 BULK-b8c92f95
14548 Bulk Product 4436d5e4 Toys & Games $969.28 446 0.0 62 BULK-01ea3f7a
14549 Bulk Product 16fe1e11 Home & Garden $789.96 302 4.8 61 BULK-861b1254
14550 Bulk Product 99dbb8b9 Books $927.14 312 1.5 71 BULK-a9eaafaf
14551 Bulk Product 81d0c9eb Toys & Games $736.30 309 3.6 89 BULK-519dc42d
14552 Bulk Product 988994e0 Sports & Outdoors $952.98 286 4.6 20 BULK-5cf6fc3b
14553 Bulk Product 1df3796a Electronics $868.08 459 0.1 36 BULK-4d12fdea
14554 Bulk Product e6d9e0c2 Sports & Outdoors $325.17 162 4.2 60 BULK-bfca3315
14555 Bulk Product b6d14a96 Sports & Outdoors $860.52 115 0.5 94 BULK-57b26ab0
14556 Bulk Product 73ffb8fb Home & Garden $442.66 410 0.6 76 BULK-93f61c98
14557 Bulk Product 99febdc8 Electronics $395.34 54 0.8 13 BULK-5e6186fa
14558 Bulk Product 796cd2e2 Books $86.88 364 4.3 79 BULK-33eaa389
14559 Bulk Product 4575842a Sports & Outdoors $302.94 263 4.9 43 BULK-d94f157c
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