Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

871 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 871 Results Showing 21751 - 21775 of 24441

ID Name Category Price Stock Rating Reviews SKU
22310 Bulk Product 9afb9aa5 Home & Garden $996.73 405 0.7 36 BULK-6995922f
22311 Bulk Product 3d5cfe89 Home & Garden $719.96 83 2.2 99 BULK-a51c45d5
22312 Bulk Product f446b3d9 Sports & Outdoors $176.68 499 4.5 18 BULK-9c8666c0
22313 Bulk Product d1251dc1 Sports & Outdoors $1,000.18 91 1.4 65 BULK-6d279b88
22314 Bulk Product b50e481e Electronics $455.23 441 0.0 31 BULK-021fd020
22315 Bulk Product 320412be Electronics $917.57 483 4.5 3 BULK-1abc9974
22316 Bulk Product ef182e18 Clothing $624.43 26 4.4 88 BULK-ea71dbe2
22317 Bulk Product 0c95d16f Electronics $734.85 367 0.7 94 BULK-f50a10be
22318 Bulk Product bc13a890 Sports & Outdoors $889.18 303 3.1 63 BULK-0e70fb47
22319 Bulk Product e0cd7e0a Home & Garden $637.23 62 1.9 50 BULK-bc581004
22320 Bulk Product 50691ef7 Sports & Outdoors $350.46 232 3.0 21 BULK-57d3fbf8
22321 Bulk Product be1b7c7b Electronics $949.44 329 0.4 2 BULK-0157b137
22322 Bulk Product 867599a4 Clothing $816.46 102 1.5 50 BULK-cc6dd69a
22323 Bulk Product d82a6f68 Electronics $197.28 316 0.6 60 BULK-35affc6f
22324 Bulk Product f1b9511d Home & Garden $27.79 133 0.7 37 BULK-7d4fe4cd
22325 Bulk Product 48d6637b Sports & Outdoors $194.68 179 4.1 16 BULK-505ffbe0
22326 Bulk Product c3b669c6 Electronics $473.88 63 4.8 51 BULK-398b255f
22327 Bulk Product 922b132d Clothing $610.76 27 4.4 40 BULK-e57fdc6d
22328 Bulk Product cd9d1d12 Home & Garden $108.74 11 2.6 52 BULK-96d06c13
22329 Bulk Product 4bfbc1a8 Home & Garden $769.33 346 2.0 75 BULK-d5477870
22330 Bulk Product c975b4ea Sports & Outdoors $264.86 253 1.4 93 BULK-649898fb
22331 Bulk Product e98d3284 Home & Garden $906.03 353 3.8 49 BULK-34e33b61
22332 Bulk Product 881d00fa Clothing $810.32 204 2.2 2 BULK-ff0003d9
22333 Bulk Product 7c83a61b Clothing $711.06 293 2.1 53 BULK-d4fbf965
22334 Bulk Product ef718b48 Books $939.13 343 1.9 44 BULK-fdd68efa
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