Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

28 ms

Page Size

25

Current Page

675 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 675 Results Showing 16851 - 16875 of 24441

ID Name Category Price Stock Rating Reviews SKU
17410 Bulk Product 746b8002 Electronics $839.58 103 3.0 36 BULK-8e1594ce
17411 Bulk Product 36ae74bb Toys & Games $875.79 132 4.6 82 BULK-120e4d20
17412 Bulk Product c37f1fc5 Sports & Outdoors $454.55 377 4.7 73 BULK-fc2dd041
17413 Bulk Product 3cbbbc9e Clothing $407.92 413 0.5 19 BULK-cdf5cd38
17414 Bulk Product 4df59edc Electronics $644.84 147 3.0 6 BULK-71523a4c
17415 Bulk Product 85519108 Sports & Outdoors $910.67 157 1.7 63 BULK-aa72a69d
17416 Bulk Product 9664e534 Electronics $416.32 72 2.0 77 BULK-eaaed591
17417 Bulk Product 820333c0 Sports & Outdoors $101.34 171 0.8 35 BULK-bf7ea0e6
17418 Bulk Product 51b7b2ce Sports & Outdoors $46.26 467 4.2 26 BULK-9ad9d02e
17419 Bulk Product d4c6ee90 Sports & Outdoors $279.15 278 5.0 14 BULK-81e4eca5
17420 Bulk Product e0bb1126 Home & Garden $773.36 381 1.7 77 BULK-81d58dc4
17421 Bulk Product fab7080d Books $504.92 84 1.9 55 BULK-17871813
17422 Bulk Product c0bd85e3 Electronics $267.31 190 0.4 60 BULK-259b8c97
17423 Bulk Product aefeaf69 Toys & Games $293.85 496 3.3 83 BULK-35a0bf30
17424 Bulk Product 101d13e3 Home & Garden $435.39 9 2.5 88 BULK-8298019d
17425 Bulk Product fd2aeab1 Sports & Outdoors $618.31 128 0.0 33 BULK-be5c4238
17426 Bulk Product 038e20b8 Electronics $888.38 266 1.9 26 BULK-a5daad55
17427 Bulk Product c940e0d1 Home & Garden $1,004.11 326 3.1 39 BULK-e6d60737
17428 Bulk Product 3dd6f853 Sports & Outdoors $938.10 482 3.9 24 BULK-334abcc7
17429 Bulk Product b5799ca5 Sports & Outdoors $326.09 241 3.3 97 BULK-4e3009c7
17430 Bulk Product fcd902ff Toys & Games $319.53 219 1.5 24 BULK-e51e6445
17431 Bulk Product 5f8bd030 Home & Garden $985.27 88 0.2 13 BULK-03460760
17432 Bulk Product 5f22ae1c Sports & Outdoors $566.98 358 2.7 64 BULK-8a93c8b2
17433 Bulk Product 74d530c0 Books $711.91 28 2.4 65 BULK-15e8e521
17434 Bulk Product 3537795e Sports & Outdoors $77.24 417 3.7 10 BULK-d83e903e
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