Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

48 ms

Page Size

25

Current Page

715 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 715 Results Showing 17851 - 17875 of 24441

ID Name Category Price Stock Rating Reviews SKU
18410 Bulk Product 61f2665f Books $189.96 245 2.6 42 BULK-b5a603e3
18411 Bulk Product e6f0bf60 Toys & Games $499.50 22 3.4 16 BULK-7e0955ad
18412 Bulk Product fb2729d8 Sports & Outdoors $326.32 464 3.1 34 BULK-293cf777
18413 Bulk Product ddc13a35 Home & Garden $805.40 401 1.8 70 BULK-db74f3a3
18414 Bulk Product c98c75fb Books $548.49 472 1.6 75 BULK-df843f4b
18415 Bulk Product 5e4ed877 Toys & Games $399.59 219 3.2 50 BULK-4d055048
18416 Bulk Product e6c4a19e Sports & Outdoors $635.33 466 3.8 85 BULK-e38c83ce
18417 Bulk Product 1f4761d1 Toys & Games $803.35 174 4.3 82 BULK-24cc14ca
18418 Bulk Product c25d6059 Toys & Games $800.57 341 4.8 9 BULK-047dd2d9
18419 Bulk Product c763e128 Electronics $176.30 316 4.0 59 BULK-79f7479c
18420 Bulk Product 3616da44 Home & Garden $37.33 465 4.6 17 BULK-1ca13679
18421 Bulk Product 9361800a Electronics $473.66 299 3.8 36 BULK-8912b601
18422 Bulk Product 29e5519a Clothing $471.01 451 2.5 34 BULK-e50cb9b8
18423 Bulk Product 707a820b Home & Garden $515.51 23 4.8 21 BULK-74b855cb
18424 Bulk Product dab17d85 Home & Garden $630.87 461 1.3 28 BULK-2c084f1d
18425 Bulk Product fb6690e1 Electronics $396.82 395 4.3 50 BULK-f30b50ef
18426 Bulk Product cefb7c4b Home & Garden $684.77 248 4.1 52 BULK-fa03d6d8
18427 Bulk Product 7449ad15 Toys & Games $932.37 442 3.6 17 BULK-a825e7ff
18428 Bulk Product 9b807d97 Toys & Games $691.81 415 2.4 23 BULK-0250afb6
18429 Bulk Product fe47eb66 Clothing $135.48 424 4.5 74 BULK-d6b7cff3
18430 Bulk Product d2f9cea4 Clothing $273.30 373 1.3 18 BULK-a587066b
18431 Bulk Product 8ee4b243 Books $561.25 256 0.6 11 BULK-6c5fe916
18432 Bulk Product e52eda52 Home & Garden $784.32 390 1.0 40 BULK-2ae69a10
18433 Bulk Product 417fa1cc Clothing $730.37 294 3.2 6 BULK-986d74b6
18434 Bulk Product 69766be9 Electronics $796.58 313 4.7 39 BULK-9e0f336a
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