Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

19 ms

Page Size

25

Current Page

553 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 553 Results Showing 13801 - 13825 of 24441

ID Name Category Price Stock Rating Reviews SKU
14360 Bulk Product d6f7db52 Electronics $423.06 43 2.1 65 BULK-a4fca358
14361 Bulk Product 420a1e1d Clothing $165.81 424 4.4 52 BULK-a8a74d23
14362 Bulk Product 1f8c8ade Electronics $68.86 277 0.0 36 BULK-e689aaad
14363 Bulk Product 059b25bb Sports & Outdoors $741.65 299 2.4 16 BULK-14cd73af
14364 Bulk Product 9135ee4f Books $376.50 97 0.7 99 BULK-97da456f
14365 Bulk Product 554953d9 Electronics $262.83 75 1.0 19 BULK-0545c9f5
14366 Bulk Product 79cb10b7 Clothing $202.23 24 0.3 3 BULK-6a0dfe70
14367 Bulk Product f59ae6a8 Electronics $290.05 209 4.8 55 BULK-5526e0fe
14368 Bulk Product 3a758a95 Books $956.80 432 3.0 68 BULK-5695860f
14369 Bulk Product 01dc4477 Clothing $822.23 344 3.6 81 BULK-970a0583
14370 Bulk Product 42ec17b5 Clothing $772.93 194 1.9 22 BULK-83184bb1
14371 Bulk Product 68380c3c Sports & Outdoors $628.91 92 4.0 53 BULK-0456e544
14372 Bulk Product 35983a3b Sports & Outdoors $528.09 243 4.7 31 BULK-864e170c
14373 Bulk Product b803b42e Toys & Games $104.67 121 4.4 11 BULK-d3b9324b
14374 Bulk Product 07191b55 Clothing $418.88 148 0.2 7 BULK-b2581651
14375 Bulk Product 346dfa2e Clothing $940.21 158 0.4 58 BULK-ecfe0154
14376 Bulk Product 8fc834ce Books $13.95 492 1.8 14 BULK-84e3fe56
14377 Bulk Product 821ac32a Sports & Outdoors $472.13 297 0.3 40 BULK-b1b20f00
14378 Bulk Product f9989cac Books $499.31 204 2.9 84 BULK-1dcf5ea2
14379 Bulk Product 5107f3cb Books $765.37 255 4.3 15 BULK-052885b3
14380 Bulk Product a7b47564 Books $626.94 445 3.9 70 BULK-a6861cd0
14381 Bulk Product faf4382d Books $661.04 445 3.7 12 BULK-ce3da5f3
14382 Bulk Product 2f6bcf32 Electronics $80.94 498 4.1 72 BULK-a074adf6
14383 Bulk Product d3c4fed1 Electronics $46.50 43 3.8 61 BULK-482442fc
14384 Bulk Product e7a3a676 Home & Garden $983.01 22 1.7 5 BULK-0b4a3d14
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