Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

55 ms

Page Size

25

Current Page

872 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 872 Results Showing 21776 - 21800 of 24441

ID Name Category Price Stock Rating Reviews SKU
22335 Bulk Product 0c56a982 Home & Garden $856.76 371 1.4 82 BULK-e5d5d301
22336 Bulk Product 04d6696d Home & Garden $840.64 385 3.7 30 BULK-8937cf77
22337 Bulk Product 36725086 Clothing $143.65 348 3.7 41 BULK-6e3527db
22338 Bulk Product 40353650 Clothing $683.02 279 0.4 9 BULK-12115a74
22339 Bulk Product 45179bb7 Electronics $415.82 413 1.5 26 BULK-a74ebb3d
22340 Bulk Product 70847c09 Sports & Outdoors $22.33 220 1.2 44 BULK-a7892117
22341 Bulk Product 659a39b9 Clothing $807.44 492 0.2 30 BULK-7cc85898
22342 Bulk Product 105ea1a1 Toys & Games $951.84 479 3.6 57 BULK-0f86f28e
22343 Bulk Product ef7fb07a Home & Garden $735.18 178 4.3 7 BULK-1669f69b
22344 Bulk Product c69b4e76 Electronics $66.15 359 2.0 23 BULK-b757daf4
22345 Bulk Product 2d67b106 Clothing $435.06 433 1.2 37 BULK-334019d1
22346 Bulk Product 29e6d47f Clothing $366.15 12 0.7 9 BULK-b8d8d3be
22347 Bulk Product ffd76d0d Sports & Outdoors $655.85 221 4.8 71 BULK-e5dc17d5
22348 Bulk Product a982f52c Books $784.20 292 1.0 59 BULK-11a75a83
22349 Bulk Product c0ecc2c3 Sports & Outdoors $624.09 103 0.6 86 BULK-8a0c2f27
22350 Bulk Product e5cf82c6 Electronics $943.92 140 2.7 87 BULK-1020990f
22351 Bulk Product b087a1fa Sports & Outdoors $613.25 380 0.3 35 BULK-9687438b
22352 Bulk Product d72038f1 Home & Garden $696.81 422 0.7 61 BULK-38cb2770
22353 Bulk Product 32d02123 Books $146.49 71 0.7 88 BULK-555cdca5
22354 Bulk Product 6e4b1465 Clothing $497.63 14 1.1 3 BULK-7f4a5154
22355 Bulk Product 227b8ce6 Home & Garden $665.11 261 2.9 62 BULK-1f664490
22356 Bulk Product 97cb80b4 Home & Garden $631.31 458 4.1 33 BULK-ed4eb02c
22357 Bulk Product 9ef662d9 Sports & Outdoors $940.09 239 2.7 29 BULK-e7254716
22358 Bulk Product 8ddb0b89 Sports & Outdoors $479.02 165 3.3 51 BULK-134ba6ce
22359 Bulk Product c541a497 Toys & Games $909.90 184 4.6 19 BULK-9fec8d14
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