Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

27 ms

Page Size

25

Current Page

726 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 726 Results Showing 18126 - 18150 of 24441

ID Name Category Price Stock Rating Reviews SKU
18685 Bulk Product 2d4c392d Clothing $586.82 295 1.8 68 BULK-e4920555
18686 Bulk Product e657461c Toys & Games $245.62 100 0.2 3 BULK-0f20f9ad
18687 Bulk Product 557fa2f9 Toys & Games $782.99 280 2.1 71 BULK-48b7bd1a
18688 Bulk Product 5a8b1d68 Electronics $114.79 259 4.2 55 BULK-38a8175f
18689 Bulk Product f4222af8 Sports & Outdoors $30.07 92 2.1 41 BULK-ddd131bc
18690 Bulk Product fd960863 Toys & Games $639.18 305 2.9 76 BULK-b0e1f007
18691 Bulk Product 158a2d1a Books $715.62 353 2.4 9 BULK-6b4a5636
18692 Bulk Product fbcf9153 Sports & Outdoors $397.70 374 0.8 96 BULK-4948b8e9
18693 Bulk Product 0cbfc3f0 Clothing $118.67 115 3.1 99 BULK-a9440e02
18694 Bulk Product 68dcac01 Electronics $686.87 74 0.6 25 BULK-4d83751d
18695 Bulk Product 706fdd31 Home & Garden $973.61 291 0.9 93 BULK-b9d01f05
18696 Bulk Product ec7c0d6e Home & Garden $224.43 101 2.0 65 BULK-6a6eddca
18697 Bulk Product e3207f27 Electronics $959.81 152 4.5 61 BULK-ac5a9b73
18698 Bulk Product c5b8b674 Toys & Games $329.02 431 1.6 71 BULK-d299e777
18699 Bulk Product 001a06c1 Electronics $185.49 238 4.8 95 BULK-05830133
18700 Bulk Product 34ca7451 Home & Garden $595.24 481 1.3 85 BULK-4045e654
18701 Bulk Product 9ad6a1d6 Toys & Games $819.23 378 3.9 4 BULK-392027a0
18702 Bulk Product 749a65a8 Electronics $73.03 439 4.4 0 BULK-17814405
18703 Bulk Product 2b08aac0 Home & Garden $178.25 390 2.2 5 BULK-0f337be5
18704 Bulk Product 36a7eeb7 Electronics $348.51 356 2.5 23 BULK-143e061f
18705 Bulk Product 502ddc13 Electronics $552.05 209 1.4 62 BULK-17c77cb3
18706 Bulk Product 819db8f5 Toys & Games $94.83 285 0.9 10 BULK-36b68c7e
18707 Bulk Product 7ea14e15 Home & Garden $811.67 386 4.8 8 BULK-8a61673c
18708 Bulk Product 5f7cc634 Clothing $180.97 135 2.6 91 BULK-5b4f531e
18709 Bulk Product 9571e49b Books $172.87 135 4.6 47 BULK-8cfbd119
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