Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

393 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 393 Results Showing 9801 - 9825 of 24441

ID Name Category Price Stock Rating Reviews SKU
10360 Bulk Product 98cd319e Electronics $620.99 402 1.5 17 BULK-7191b095
10361 Bulk Product 2de29453 Clothing $961.23 68 0.2 28 BULK-c0653e8e
10362 Bulk Product eb453073 Sports & Outdoors $634.05 388 0.1 36 BULK-2b604157
10363 Bulk Product 8b149e38 Toys & Games $712.32 60 2.7 66 BULK-cd266282
10364 Bulk Product 3614f98b Electronics $39.97 372 0.3 17 BULK-fc172bfe
10365 Bulk Product 8bc71e7b Home & Garden $171.29 228 3.2 45 BULK-6f448456
10366 Bulk Product ae55a65d Electronics $10.99 340 0.8 81 BULK-e9dc3eb9
10367 Bulk Product 3ccf7cd0 Books $755.63 451 3.1 20 BULK-9f5a98eb
10368 Bulk Product f012a192 Clothing $864.19 226 3.7 75 BULK-f109b0da
10369 Bulk Product 1a617a43 Electronics $640.54 394 4.8 60 BULK-44b9ef56
10370 Bulk Product 3f696895 Home & Garden $701.83 27 3.9 6 BULK-f873e845
10371 Bulk Product 7cdbd9fe Clothing $660.99 19 0.7 91 BULK-1a71f87d
10372 Bulk Product 7e6c3632 Electronics $665.15 378 4.4 10 BULK-18225be9
10373 Bulk Product d8c3a031 Clothing $303.15 481 1.9 34 BULK-cb25a7f3
10374 Bulk Product 9a04d0c0 Books $327.34 56 3.1 31 BULK-c92b2a0b
10375 Bulk Product 883ed936 Home & Garden $384.05 361 0.5 77 BULK-827eac0c
10376 Bulk Product 4e1587fc Clothing $973.59 462 1.9 9 BULK-12e6da2a
10377 Bulk Product 0569ed6d Home & Garden $448.71 381 1.0 67 BULK-93254885
10378 Bulk Product 35d46e18 Toys & Games $198.43 476 2.8 92 BULK-bc580fd9
10379 Bulk Product 8c6e613c Electronics $38.96 92 1.0 59 BULK-95c8e934
10380 Bulk Product c4505daa Toys & Games $496.91 345 3.3 62 BULK-9d69ded9
10381 Bulk Product 4d88a3bb Sports & Outdoors $723.83 357 4.2 35 BULK-680d78c0
10382 Bulk Product 2db93793 Electronics $919.85 123 1.4 53 BULK-e9a210db
10383 Bulk Product 413ae7f9 Home & Garden $568.49 434 1.0 43 BULK-f69b1900
10384 Bulk Product 14687b5d Books $776.45 183 2.7 76 BULK-2e14544e
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