Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

16 ms

Page Size

25

Current Page

555 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 555 Results Showing 13851 - 13875 of 24441

ID Name Category Price Stock Rating Reviews SKU
14410 Bulk Product cf8bac1f Home & Garden $380.32 104 1.1 0 BULK-e4e3157c
14411 Bulk Product e022c31e Sports & Outdoors $638.93 175 2.4 10 BULK-e33fc341
14412 Bulk Product 190af85f Toys & Games $804.04 269 1.0 46 BULK-e072efdb
14413 Bulk Product 0671d8d9 Books $20.58 168 4.2 87 BULK-e21383a1
14414 Bulk Product 62d0b791 Home & Garden $412.31 297 2.9 87 BULK-7a2d7169
14415 Bulk Product 0e651b94 Sports & Outdoors $15.85 94 4.6 68 BULK-9c00dd0f
14416 Bulk Product 2fe07f34 Clothing $176.87 293 1.6 12 BULK-d1daa9d5
14417 Bulk Product 42011102 Sports & Outdoors $609.70 74 0.4 12 BULK-f3a4426a
14418 Bulk Product a92c837e Books $53.28 1 0.9 1 BULK-15ec31a4
14419 Bulk Product 224589e4 Home & Garden $96.33 69 3.1 89 BULK-fd1d0595
14420 Bulk Product 4caacada Toys & Games $350.68 280 1.8 39 BULK-6e4984da
14421 Bulk Product 19cb3ade Toys & Games $335.32 423 0.3 71 BULK-6fbd40c7
14422 Bulk Product 593387d5 Clothing $420.47 375 1.7 72 BULK-fe0070f3
14423 Bulk Product 011a44b0 Toys & Games $654.31 260 3.9 56 BULK-f233b36c
14424 Bulk Product 14e799a6 Books $191.78 406 2.6 16 BULK-d6363425
14425 Bulk Product 2371f15c Sports & Outdoors $916.69 463 0.6 20 BULK-8ce16d93
14426 Bulk Product e4ae6c93 Books $604.90 387 5.0 46 BULK-4b13a15f
14427 Bulk Product 4fe82750 Clothing $529.56 265 0.4 61 BULK-325f3c59
14428 Bulk Product c8c7a2d6 Sports & Outdoors $999.58 271 1.6 58 BULK-243415d4
14429 Bulk Product 19837790 Electronics $780.15 0 1.5 35 BULK-83bde26f
14430 Bulk Product 6f126079 Clothing $220.86 56 1.2 14 BULK-48d240bb
14431 Bulk Product a40628c1 Clothing $740.46 128 3.4 37 BULK-4024dfb3
14432 Bulk Product 4c079a4a Home & Garden $777.09 82 1.9 4 BULK-fab3316d
14433 Bulk Product 1c9c867b Electronics $604.90 270 2.0 41 BULK-ef24ed17
14434 Bulk Product d366d158 Electronics $867.74 251 0.0 61 BULK-227c8a39
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