Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

68 ms

Page Size

25

Current Page

897 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 897 Results Showing 22401 - 22425 of 24441

ID Name Category Price Stock Rating Reviews SKU
22960 Bulk Product 5976ec26 Electronics $637.13 303 1.0 54 BULK-f7eb4c9e
22961 Bulk Product b54116d9 Sports & Outdoors $575.71 247 4.5 91 BULK-44bb1e87
22962 Bulk Product 75e8a0de Books $499.64 489 1.9 47 BULK-9b618608
22963 Bulk Product 5049f063 Sports & Outdoors $785.43 453 3.1 29 BULK-566848b8
22964 Bulk Product 980b59cc Books $487.78 29 4.7 79 BULK-4c3025ca
22965 Bulk Product 31d7f73f Home & Garden $355.92 225 1.9 72 BULK-3d71fd75
22966 Bulk Product 1842134f Sports & Outdoors $390.46 384 0.8 26 BULK-0bb47a51
22967 Bulk Product bba802ec Toys & Games $224.56 232 2.0 34 BULK-f08e3d26
22968 Bulk Product 8c028e65 Toys & Games $374.66 127 1.7 55 BULK-a534ee2f
22969 Bulk Product b018475b Sports & Outdoors $168.52 460 4.0 50 BULK-a885f16e
22970 Bulk Product d1d930cd Home & Garden $815.92 136 0.9 17 BULK-9a07e9f7
22971 Bulk Product d9f16acf Toys & Games $407.34 325 3.5 55 BULK-06035a46
22972 Bulk Product 0ba14421 Home & Garden $251.54 303 2.3 86 BULK-4e691c9b
22973 Bulk Product 21994e5d Sports & Outdoors $936.53 81 0.7 12 BULK-4f2795ba
22974 Bulk Product 07996ca5 Electronics $976.99 199 0.9 12 BULK-df39d813
22975 Bulk Product 167348c1 Home & Garden $410.11 410 4.4 77 BULK-47920ec7
22976 Bulk Product aab5dece Electronics $685.37 429 4.7 19 BULK-b717ed9b
22977 Bulk Product c379099e Home & Garden $983.03 80 3.2 72 BULK-9c19d525
22978 Bulk Product 138569d7 Home & Garden $637.27 167 1.2 68 BULK-18d238d7
22979 Bulk Product 39931af3 Books $240.38 215 1.0 85 BULK-1e188daf
22980 Bulk Product 30948161 Toys & Games $627.86 200 4.0 19 BULK-60afde80
22981 Bulk Product 7f1d9d10 Sports & Outdoors $628.24 202 2.2 84 BULK-3f72c40f
22982 Bulk Product 4bc4b770 Home & Garden $955.79 192 3.4 31 BULK-466bc4b1
22983 Bulk Product 9492df2b Books $27.90 339 3.7 88 BULK-5f75b510
22984 Bulk Product 9dd56142 Books $244.75 343 4.3 5 BULK-711c96c8
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