Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

39 ms

Page Size

25

Current Page

604 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 604 Results Showing 15076 - 15100 of 24441

ID Name Category Price Stock Rating Reviews SKU
15635 Bulk Product 078abe1b Books $155.54 159 1.1 0 BULK-164bb2cc
15636 Bulk Product b0f0d47a Sports & Outdoors $363.60 292 1.4 13 BULK-f475306a
15637 Bulk Product 0b159be7 Clothing $831.32 498 4.6 67 BULK-4dbc9e54
15638 Bulk Product 66c0eb91 Books $538.98 160 1.3 26 BULK-c3b97a7a
15639 Bulk Product 5f7f48a2 Clothing $421.98 368 4.2 66 BULK-962b6b80
15640 Bulk Product 60e65cfa Sports & Outdoors $890.88 164 3.5 85 BULK-69199d14
15641 Bulk Product aeaed84e Books $56.16 95 4.3 42 BULK-b3c27f6e
15642 Bulk Product 7047f2f6 Electronics $693.28 33 3.7 83 BULK-c978e4aa
15643 Bulk Product 6adfe77a Home & Garden $287.99 476 3.1 35 BULK-b6e4d2e5
15644 Bulk Product 24286985 Books $635.83 127 4.7 25 BULK-1a5888e2
15645 Bulk Product 35d1e462 Clothing $646.96 24 4.7 68 BULK-1fc07c3e
15646 Bulk Product dfd0005f Electronics $107.09 22 4.0 51 BULK-6c7bda3e
15647 Bulk Product 019aa7f0 Sports & Outdoors $353.60 41 0.5 77 BULK-fddd61a6
15648 Bulk Product e0d2c1f4 Sports & Outdoors $66.54 158 0.6 12 BULK-cbf5f0c0
15649 Bulk Product f852f9d8 Clothing $722.56 41 1.5 99 BULK-2b038b60
15650 Bulk Product c3d9854e Electronics $953.25 229 1.6 63 BULK-671b43f7
15651 Bulk Product 8e04fa89 Books $433.51 190 3.7 71 BULK-2d9456b1
15652 Bulk Product e6850a6c Sports & Outdoors $924.07 199 3.6 30 BULK-7eb6d927
15653 Bulk Product 8c729dac Books $95.76 305 1.0 65 BULK-4f80012a
15654 Bulk Product cbb387c1 Home & Garden $724.03 11 3.3 11 BULK-85768d8f
15655 Bulk Product 097a6455 Home & Garden $674.88 114 4.9 38 BULK-db96509e
15656 Bulk Product 6aa52e12 Books $801.59 231 1.6 97 BULK-2d2849ef
15657 Bulk Product d9c49779 Clothing $187.35 157 3.2 96 BULK-2b9caa82
15658 Bulk Product aee08eac Books $300.85 137 1.5 47 BULK-49141a52
15659 Bulk Product 7ee5358b Toys & Games $323.35 20 1.8 49 BULK-39a2d38e
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