Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

44 ms

Page Size

25

Current Page

886 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 886 Results Showing 22126 - 22150 of 24441

ID Name Category Price Stock Rating Reviews SKU
22685 Bulk Product 9cd56e84 Toys & Games $650.02 387 0.5 86 BULK-9f021dcf
22686 Bulk Product daed61c1 Home & Garden $333.38 130 2.5 30 BULK-7d5445d1
22687 Bulk Product ed6c785d Books $374.28 404 1.9 79 BULK-12eb91cd
22688 Bulk Product dc98933f Clothing $819.43 396 2.5 7 BULK-d390cb21
22689 Bulk Product 491dd14a Home & Garden $724.45 378 2.4 53 BULK-c1c6890f
22690 Bulk Product b53e8a5c Home & Garden $633.97 150 3.5 59 BULK-5fa0b7d4
22691 Bulk Product 6c26892e Home & Garden $454.09 189 2.0 77 BULK-6c155e8d
22692 Bulk Product de171ff2 Toys & Games $238.13 105 1.9 28 BULK-3aac00c6
22693 Bulk Product 3f25099d Sports & Outdoors $430.52 307 2.3 10 BULK-497b7ce1
22694 Bulk Product 07b90f5a Home & Garden $87.48 492 4.6 84 BULK-8fae9943
22695 Bulk Product 2a923db2 Electronics $45.40 20 2.8 42 BULK-e36077d2
22696 Bulk Product 7bfb7c55 Clothing $356.24 0 4.4 8 BULK-c63816a0
22697 Bulk Product e3016e5a Toys & Games $654.35 232 4.6 54 BULK-a9e6b6ee
22698 Bulk Product ff7b03ad Books $264.81 346 4.5 12 BULK-23ee033d
22699 Bulk Product 7b8f6477 Sports & Outdoors $833.16 42 1.4 37 BULK-ea5bd452
22700 Bulk Product 156ab0d8 Books $675.87 252 2.1 25 BULK-1b0a2782
22701 Bulk Product 3a6ec443 Sports & Outdoors $412.28 368 4.6 85 BULK-1e7d658d
22702 Bulk Product 4055a3a7 Books $823.68 236 0.3 18 BULK-ec9d4307
22703 Bulk Product 6fcdfeee Home & Garden $149.46 185 0.5 47 BULK-17b4100d
22704 Bulk Product 33f3fd21 Home & Garden $335.55 472 4.8 42 BULK-1f5bacda
22705 Bulk Product f25e5eb9 Books $412.83 103 1.9 8 BULK-030e79c2
22706 Bulk Product 4a5edfb6 Clothing $88.32 395 3.1 3 BULK-e8ef3731
22707 Bulk Product df81e2ae Home & Garden $429.36 196 0.3 96 BULK-c573be2e
22708 Bulk Product 5b678382 Toys & Games $49.43 96 3.4 94 BULK-9432f332
22709 Bulk Product ee96ea55 Books $348.37 361 4.5 84 BULK-a259e881
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