Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

286 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 286 Results Showing 7126 - 7150 of 24441

ID Name Category Price Stock Rating Reviews SKU
7685 Bulk Product d2dbe45b Clothing $334.51 417 2.8 68 BULK-e4b01430
7686 Bulk Product 1a0347f8 Toys & Games $378.38 148 0.8 93 BULK-1eec6545
7687 Bulk Product f404eaa9 Sports & Outdoors $857.70 291 2.6 39 BULK-95e0a053
7688 Bulk Product 076c4e93 Sports & Outdoors $645.75 432 3.6 97 BULK-b18eb5f6
7689 Bulk Product 56fc2374 Toys & Games $280.39 236 0.0 17 BULK-3b7728e3
7690 Bulk Product 40625909 Books $776.30 498 2.0 78 BULK-9336d094
7691 Bulk Product 16d1ae0d Toys & Games $986.36 74 2.9 47 BULK-686a8e00
7692 Bulk Product 7715e55f Home & Garden $512.09 2 1.7 36 BULK-0c853889
7693 Bulk Product 7a4a67f0 Toys & Games $631.38 12 0.1 10 BULK-7ab53eab
7694 Bulk Product 2f09e982 Sports & Outdoors $495.87 29 2.0 5 BULK-8d9af956
7695 Bulk Product 352f7f3a Sports & Outdoors $288.57 458 4.3 15 BULK-b564c0a1
7696 Bulk Product f321a119 Books $589.43 6 2.1 2 BULK-c3960258
7697 Bulk Product 9491d3fe Electronics $734.31 350 1.3 24 BULK-b7006b76
7698 Bulk Product 912a3e46 Home & Garden $478.08 11 0.9 58 BULK-075b2d57
7699 Bulk Product 66b2b7a4 Clothing $814.47 92 2.1 90 BULK-2c9951fe
7700 Bulk Product 61d67410 Electronics $914.72 300 3.9 53 BULK-ed556423
7701 Bulk Product 8d05d214 Books $96.49 271 0.4 16 BULK-1eb00b4a
7702 Bulk Product 642afb48 Home & Garden $133.73 422 1.4 41 BULK-f20f1c9f
7703 Bulk Product 0df17175 Home & Garden $583.76 491 2.9 32 BULK-f1456e3d
7704 Bulk Product f497510f Toys & Games $131.55 287 0.8 70 BULK-790ccdde
7705 Bulk Product 1cc0d063 Sports & Outdoors $286.55 321 4.4 66 BULK-8488cb12
7706 Bulk Product 47e42fa4 Toys & Games $204.01 423 3.0 38 BULK-6036c519
7707 Bulk Product e2fc3891 Sports & Outdoors $678.48 348 1.2 55 BULK-3b4ff48f
7708 Bulk Product 9812d18a Toys & Games $630.31 171 2.1 52 BULK-b337d6ea
7709 Bulk Product 28affaec Home & Garden $806.40 428 2.0 15 BULK-f0734e8c
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