Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

122 ms

Page Size

25

Current Page

191 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 191 Results Showing 4751 - 4775 of 24441

ID Name Category Price Stock Rating Reviews SKU
5310 Bulk Product 6c1ac4ee Books $640.70 90 5.0 10 BULK-c28c29f1
5311 Bulk Product 6fa4112b Sports & Outdoors $174.12 305 2.7 13 BULK-c7295ef8
5312 Bulk Product 305acd8b Sports & Outdoors $10.97 273 0.4 5 BULK-6706bb54
5313 Bulk Product 7210a8e0 Home & Garden $413.88 428 1.2 62 BULK-8dc5bb6d
5314 Bulk Product 9b8f29e4 Electronics $64.78 262 3.2 31 BULK-4dd11482
5315 Bulk Product 624ae15e Home & Garden $402.71 218 3.0 95 BULK-111e4b87
5316 Bulk Product 271c9bf6 Sports & Outdoors $142.78 157 4.6 75 BULK-90eee821
5317 Bulk Product 59b03f50 Home & Garden $35.29 460 4.5 80 BULK-c3d1d164
5318 Bulk Product 1977e160 Home & Garden $108.19 397 3.1 76 BULK-c82e316a
5319 Bulk Product f79a6d27 Books $465.05 450 4.1 53 BULK-7c575cff
5320 Bulk Product 2244c16a Home & Garden $621.02 242 0.8 75 BULK-57715bff
5321 Bulk Product 4f258155 Home & Garden $259.51 88 1.4 7 BULK-455f4df7
5322 Bulk Product 2deb894c Toys & Games $897.66 387 2.7 16 BULK-e28e7de9
5323 Bulk Product 9c96d854 Sports & Outdoors $126.04 73 0.1 92 BULK-d2c0d2f8
5324 Bulk Product 7382e7c2 Sports & Outdoors $978.39 9 2.9 99 BULK-05457ba8
5325 Bulk Product cf949958 Toys & Games $706.84 105 0.9 77 BULK-0a1a90ff
5326 Bulk Product e5d4f969 Home & Garden $136.62 296 1.6 4 BULK-935d1722
5327 Bulk Product 08244dcf Clothing $116.03 436 3.8 87 BULK-41884963
5328 Bulk Product 9a3afc38 Toys & Games $781.38 366 3.8 99 BULK-7e018c75
5329 Bulk Product 8a6c3483 Toys & Games $185.12 468 3.5 72 BULK-6896f662
5330 Bulk Product d6c497be Home & Garden $372.85 138 2.7 41 BULK-51460de0
5331 Bulk Product d9c7f91e Books $588.04 374 2.5 27 BULK-b3edf235
5332 Bulk Product c5ffcea9 Home & Garden $671.13 497 1.6 86 BULK-3584091a
5333 Bulk Product f0559c41 Home & Garden $101.17 135 3.9 32 BULK-223dace9
5334 Bulk Product f8dd2d0a Electronics $147.19 394 2.2 58 BULK-f6575252
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