Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

50 ms

Page Size

25

Current Page

550 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 550 Results Showing 13726 - 13750 of 24441

ID Name Category Price Stock Rating Reviews SKU
14285 Bulk Product 16e1d187 Electronics $758.05 298 0.9 26 BULK-9e443028
14286 Bulk Product d1712e28 Toys & Games $1,003.73 418 4.6 33 BULK-ebd70f33
14287 Bulk Product f0cf04d0 Electronics $89.17 372 2.1 66 BULK-0411460f
14288 Bulk Product 6123db4b Sports & Outdoors $578.47 78 1.7 51 BULK-b68a647b
14289 Bulk Product 96860b7f Clothing $23.96 492 0.3 6 BULK-969f83b4
14290 Bulk Product 694126c0 Electronics $60.28 466 2.0 91 BULK-ed53af12
14291 Bulk Product 07049741 Books $558.83 102 5.0 41 BULK-166cd1bc
14292 Bulk Product 4da2600f Home & Garden $883.24 429 2.8 33 BULK-9b586e02
14293 Bulk Product 9626db98 Clothing $570.61 50 0.1 9 BULK-825ad00f
14294 Bulk Product 7f6c7783 Toys & Games $441.08 249 3.4 71 BULK-9ecbe0e5
14295 Bulk Product 7d8bd1df Toys & Games $321.41 244 4.3 47 BULK-a7d99a5e
14296 Bulk Product 53925128 Books $129.99 496 1.7 67 BULK-0a2c1bd3
14297 Bulk Product ae74d34e Electronics $328.79 364 2.7 54 BULK-0e42b68f
14298 Bulk Product 6c9a3c4e Toys & Games $980.05 23 1.4 92 BULK-80b23ac6
14299 Bulk Product 2a397e5f Sports & Outdoors $716.72 27 1.6 87 BULK-84f42d0d
14300 Bulk Product f5e63e23 Toys & Games $900.37 400 3.7 29 BULK-f724f723
14301 Bulk Product f8e53ff4 Clothing $456.04 449 0.2 78 BULK-91f7e813
14302 Bulk Product a9953c74 Toys & Games $1,008.17 148 1.7 63 BULK-04ee0eab
14303 Bulk Product 44b4d108 Electronics $259.91 60 3.6 31 BULK-9c3e8a44
14304 Bulk Product 3b4540ba Toys & Games $463.59 299 3.7 35 BULK-69b09d98
14305 Bulk Product a739832c Electronics $280.99 39 3.0 11 BULK-d518a0c0
14306 Bulk Product e45e5977 Toys & Games $20.93 360 1.2 98 BULK-af7e3a27
14307 Bulk Product 7c1f6b82 Electronics $247.89 397 2.1 42 BULK-5c386d26
14308 Bulk Product c3e259b5 Books $103.16 172 2.5 98 BULK-9a0e3717
14309 Bulk Product b6c34659 Home & Garden $792.26 254 2.4 96 BULK-56a2536a
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