Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

368 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 368 Results Showing 9176 - 9200 of 24441

ID Name Category Price Stock Rating Reviews SKU
9735 Bulk Product 48e9b2a0 Sports & Outdoors $373.48 266 1.2 97 BULK-3570fc23
9736 Bulk Product a5c75db3 Toys & Games $799.38 299 1.1 70 BULK-a7e90c78
9737 Bulk Product e4451901 Electronics $632.81 89 0.0 93 BULK-e283ee74
9738 Bulk Product ca317c9a Sports & Outdoors $205.00 89 0.7 90 BULK-c77716ac
9739 Bulk Product 90b00257 Electronics $453.21 84 0.7 74 BULK-78728a52
9740 Bulk Product 4038de7e Toys & Games $881.49 432 2.6 41 BULK-1522565c
9741 Bulk Product 8f5803e8 Books $640.64 414 2.0 87 BULK-d816d00c
9742 Bulk Product ea541110 Toys & Games $990.89 489 4.4 8 BULK-6e30f104
9743 Bulk Product eab840e0 Clothing $189.52 68 4.6 32 BULK-5b77dd8d
9744 Bulk Product 0efebd9e Toys & Games $959.90 108 1.4 16 BULK-333206d8
9745 Bulk Product 750a41ce Clothing $387.48 183 4.7 0 BULK-2de1d70a
9746 Bulk Product 6cb6b828 Sports & Outdoors $143.59 278 2.5 16 BULK-fb574766
9747 Bulk Product 23732d34 Clothing $602.03 293 2.0 73 BULK-0a79b7b7
9748 Bulk Product 0abe292b Toys & Games $608.83 144 2.8 99 BULK-8137ac0b
9749 Bulk Product a2acae00 Electronics $1,003.86 323 1.6 41 BULK-601d8bb2
9750 Bulk Product 136e96bf Clothing $859.76 252 4.2 60 BULK-3f965758
9751 Bulk Product c2fa1693 Toys & Games $48.20 22 2.5 31 BULK-b3c471bd
9752 Bulk Product 74b76010 Toys & Games $659.36 223 1.6 27 BULK-1ff68c8b
9753 Bulk Product 30a1ce8f Electronics $94.95 487 1.7 20 BULK-6e9203d2
9754 Bulk Product ba92aa7d Home & Garden $371.22 192 1.9 70 BULK-5600025b
9755 Bulk Product 4db3e2a1 Sports & Outdoors $129.52 465 3.3 92 BULK-ff76b6e4
9756 Bulk Product 1ed3bb5f Electronics $22.39 270 0.5 1 BULK-fd058fb6
9757 Bulk Product 2f04be78 Toys & Games $744.84 100 2.6 67 BULK-e87c63d2
9758 Bulk Product f8163996 Sports & Outdoors $381.37 416 2.4 67 BULK-b4ce30c3
9759 Bulk Product d75d07db Books $147.95 73 2.0 18 BULK-d2a4b2f1
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