Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

543 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 543 Results Showing 13551 - 13575 of 24441

ID Name Category Price Stock Rating Reviews SKU
14110 Bulk Product 5f1225dd Sports & Outdoors $808.39 146 0.7 79 BULK-17cffc09
14111 Bulk Product 0ed92c0e Books $120.31 157 0.9 91 BULK-6afab2c9
14112 Bulk Product 40973f9e Books $646.68 14 0.3 18 BULK-b29a8b61
14113 Bulk Product 99e7fe53 Books $342.35 82 3.0 11 BULK-ba432b6b
14114 Bulk Product 5a5a9b2a Toys & Games $866.34 387 5.0 46 BULK-5ab844e0
14115 Bulk Product f2796138 Toys & Games $578.48 275 2.4 72 BULK-673ddd7a
14116 Bulk Product f57dc92d Sports & Outdoors $199.81 376 4.0 53 BULK-c5b01787
14117 Bulk Product ad4ea277 Clothing $159.70 104 3.1 92 BULK-6a3619ec
14118 Bulk Product 261e5f9e Books $140.77 150 3.5 46 BULK-6b2d26a9
14119 Bulk Product dc27b57d Toys & Games $435.66 273 4.7 70 BULK-b4891413
14120 Bulk Product 0bbeca3a Home & Garden $449.16 214 3.2 82 BULK-0c47e5f0
14121 Bulk Product 438d4d21 Sports & Outdoors $601.66 482 1.5 20 BULK-5a317851
14122 Bulk Product 0a58ea5c Electronics $511.71 223 1.1 74 BULK-e4c46a72
14123 Bulk Product 3ea9d58a Books $501.28 268 0.0 76 BULK-0aa46b76
14124 Bulk Product 5370a76e Home & Garden $667.95 437 0.1 7 BULK-15d0eeb6
14125 Bulk Product 397745ea Electronics $568.05 355 1.5 27 BULK-5300d8f1
14126 Bulk Product 4ad5009f Home & Garden $314.29 486 4.9 98 BULK-822c9b60
14127 Bulk Product 56c99ee6 Electronics $939.06 92 1.1 95 BULK-95bf4c43
14128 Bulk Product 88e6f0ac Electronics $675.03 397 1.8 97 BULK-45c34987
14129 Bulk Product 2a796312 Toys & Games $628.01 330 2.0 60 BULK-5d3491c6
14130 Bulk Product e727f747 Sports & Outdoors $396.03 204 2.4 38 BULK-05158424
14131 Bulk Product 1310b1f9 Home & Garden $288.76 485 4.6 57 BULK-93278b9c
14132 Bulk Product cb017003 Home & Garden $362.51 274 2.8 89 BULK-3dc66ad3
14133 Bulk Product b2ac8bdb Home & Garden $396.25 457 3.0 47 BULK-64905910
14134 Bulk Product e3b6fb1e Toys & Games $127.92 130 2.7 81 BULK-4f68b070
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