Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

43 ms

Page Size

25

Current Page

192 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 192 Results Showing 4776 - 4800 of 24441

ID Name Category Price Stock Rating Reviews SKU
5335 Bulk Product 5209c04d Sports & Outdoors $56.40 406 1.5 3 BULK-f0d01a47
5336 Bulk Product 4d7f693c Sports & Outdoors $78.73 388 2.4 52 BULK-1ac5f726
5337 Bulk Product 00923ce2 Toys & Games $757.77 488 0.6 28 BULK-a9782652
5338 Bulk Product 0efe6238 Sports & Outdoors $166.81 353 2.7 63 BULK-79fdd837
5339 Bulk Product 7d58c207 Books $664.44 42 4.2 39 BULK-2f5097f6
5340 Bulk Product 92ed32a2 Clothing $740.00 349 2.4 28 BULK-08a957bb
5341 Bulk Product 47af95a8 Home & Garden $186.58 109 1.4 65 BULK-35828bd2
5342 Bulk Product 43a8def0 Home & Garden $307.88 461 2.5 9 BULK-a8e9e83c
5343 Bulk Product 77c11786 Home & Garden $532.29 306 3.9 76 BULK-383c3887
5344 Bulk Product 2bff336c Clothing $189.67 276 2.4 35 BULK-ba07f989
5345 Bulk Product 7ae3e59c Clothing $890.65 491 1.7 7 BULK-47650f8b
5346 Bulk Product 715ed3a0 Home & Garden $363.39 404 0.7 58 BULK-b70b5372
5347 Bulk Product 7c63a580 Sports & Outdoors $444.90 319 0.6 66 BULK-96e75d1d
5348 Bulk Product c049f52f Clothing $299.61 59 1.2 46 BULK-ed94dca9
5349 Bulk Product 7a2a03a3 Home & Garden $991.96 175 0.3 73 BULK-094d6249
5350 Bulk Product 274b6a5c Electronics $153.14 42 3.1 38 BULK-c74e2604
5351 Bulk Product cc3f5a06 Books $174.63 170 4.9 77 BULK-c4935d87
5352 Bulk Product 5d365ffa Home & Garden $57.60 496 2.5 81 BULK-049d7137
5353 Bulk Product e631f45f Books $155.92 472 0.9 13 BULK-b1b3ca94
5354 Bulk Product 8440ec62 Electronics $791.84 61 1.8 5 BULK-a10499b3
5355 Bulk Product 229f400c Toys & Games $318.68 121 2.4 69 BULK-ede247ad
5356 Bulk Product e1f3362c Clothing $194.56 383 3.2 73 BULK-4d61ff47
5357 Bulk Product 875791d5 Home & Garden $221.43 279 0.9 60 BULK-d5c3ebb7
5358 Bulk Product b2369eb9 Clothing $787.73 312 2.6 90 BULK-3c45af47
5359 Bulk Product fd37e8fd Clothing $329.15 350 2.1 8 BULK-499d9075
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