Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

32 ms

Page Size

25

Current Page

680 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 680 Results Showing 16976 - 17000 of 24441

ID Name Category Price Stock Rating Reviews SKU
17535 Bulk Product 1f2fbbc9 Toys & Games $625.12 140 0.7 21 BULK-effb0bbc
17536 Bulk Product e8d528c2 Books $136.96 346 1.7 9 BULK-5418ab3d
17537 Bulk Product 363f5052 Clothing $842.80 220 0.3 54 BULK-8f6e6a68
17538 Bulk Product 04a51a1e Books $670.09 280 0.8 78 BULK-334d439d
17539 Bulk Product 2103ad77 Home & Garden $718.10 208 0.5 36 BULK-0d4e9de6
17540 Bulk Product 7c851ce3 Clothing $660.38 431 4.8 27 BULK-beb99481
17541 Bulk Product e05aece3 Toys & Games $81.55 425 4.0 55 BULK-08c2105a
17542 Bulk Product 21768623 Sports & Outdoors $81.71 285 3.2 51 BULK-d0cd3fda
17543 Bulk Product aab8036c Home & Garden $804.44 222 2.1 47 BULK-4c673450
17544 Bulk Product 598fac96 Books $18.01 148 2.2 85 BULK-6a093515
17545 Bulk Product 2667d557 Sports & Outdoors $749.25 333 2.1 26 BULK-fe987008
17546 Bulk Product 79ed301c Books $379.92 361 2.5 9 BULK-d308a0d9
17547 Bulk Product 4ac80f61 Electronics $716.68 262 1.0 45 BULK-bf03dc67
17548 Bulk Product 741fed8f Books $188.57 299 0.7 26 BULK-78caaa4d
17549 Bulk Product ed6117b9 Electronics $265.73 39 0.1 60 BULK-907caa4c
17550 Bulk Product 58ec7d6e Electronics $603.92 212 3.4 83 BULK-d777f7bb
17551 Bulk Product f528a528 Sports & Outdoors $285.39 286 4.5 70 BULK-19f0c16f
17552 Bulk Product 79a82e00 Toys & Games $430.67 149 3.6 33 BULK-81a3d947
17553 Bulk Product 9fe21fdf Toys & Games $400.38 344 1.5 56 BULK-8e7002d7
17554 Bulk Product 955888bf Clothing $786.44 80 0.3 14 BULK-451407f7
17555 Bulk Product e9057b3d Home & Garden $40.55 111 0.7 86 BULK-1c38ae62
17556 Bulk Product 94934f27 Toys & Games $607.94 378 1.6 95 BULK-4184a255
17557 Bulk Product ace05767 Electronics $829.38 421 4.1 22 BULK-58c0513e
17558 Bulk Product 6c26fa18 Books $598.31 299 2.1 63 BULK-3e744aa3
17559 Bulk Product 8c86f71d Electronics $529.69 77 4.8 2 BULK-ff6d4bb9
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