Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

527 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 527 Results Showing 13151 - 13175 of 24441

ID Name Category Price Stock Rating Reviews SKU
13710 Bulk Product d50e6e05 Books $210.44 489 4.3 51 BULK-d96a9773
13711 Bulk Product 6089ad48 Toys & Games $440.21 36 0.7 16 BULK-75f85aed
13712 Bulk Product d0355c56 Sports & Outdoors $737.14 443 2.4 30 BULK-c1de76f8
13713 Bulk Product 8defe3a9 Sports & Outdoors $955.58 199 2.7 16 BULK-bd992652
13714 Bulk Product b4eb1efd Books $524.87 431 4.4 42 BULK-97990ef3
13715 Bulk Product 566865aa Books $972.28 46 3.1 2 BULK-0e7f513a
13716 Bulk Product 4d9804d1 Clothing $845.19 287 0.2 16 BULK-80a49182
13717 Bulk Product 1f036328 Clothing $979.72 346 0.6 22 BULK-c600a196
13718 Bulk Product 2527cbee Electronics $472.79 121 1.5 10 BULK-e0d4bf07
13719 Bulk Product 4bea848b Electronics $388.00 5 0.3 35 BULK-c3e6fc32
13720 Bulk Product 697fc562 Clothing $638.23 452 1.7 46 BULK-a6d2aee6
13721 Bulk Product 30c63d89 Toys & Games $546.76 193 4.7 29 BULK-7defba92
13722 Bulk Product 5eb0c45e Home & Garden $34.63 274 3.6 48 BULK-9069e87b
13723 Bulk Product 4c62cdce Books $566.83 484 4.5 19 BULK-c86a0159
13724 Bulk Product 17f3bd55 Books $15.87 470 3.7 30 BULK-e6771e6c
13725 Bulk Product 616c4985 Sports & Outdoors $286.95 485 2.6 37 BULK-2962567b
13726 Bulk Product 7c9a905b Sports & Outdoors $445.85 376 0.9 13 BULK-645bc868
13727 Bulk Product 9a89e664 Sports & Outdoors $760.06 382 3.1 71 BULK-c1993627
13728 Bulk Product fbbfe8ba Sports & Outdoors $670.36 324 3.6 6 BULK-18c3e682
13729 Bulk Product 460d3de2 Books $654.77 66 2.3 40 BULK-36ee9c29
13730 Bulk Product e05784b7 Electronics $412.54 144 4.1 31 BULK-d99bddf5
13731 Bulk Product cb8900e1 Electronics $780.11 293 0.5 21 BULK-c5ab6952
13732 Bulk Product ee96c9eb Home & Garden $737.07 280 0.6 24 BULK-181f6d93
13733 Bulk Product bb5fa6c1 Electronics $366.29 311 1.5 2 BULK-24fd733f
13734 Bulk Product 6dff58fa Clothing $712.28 14 3.1 88 BULK-1c40428e
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