Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

65 ms

Page Size

25

Current Page

923 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 923 Results Showing 23051 - 23075 of 24441

ID Name Category Price Stock Rating Reviews SKU
23610 Bulk Product 240ed601 Home & Garden $61.24 4 3.5 56 BULK-fe269744
23611 Bulk Product b3263cbb Home & Garden $170.00 495 0.6 9 BULK-346f6f06
23612 Bulk Product aad9134d Books $86.71 317 1.1 75 BULK-42f3974e
23613 Bulk Product 41f63a0b Toys & Games $864.49 477 2.3 18 BULK-8ee65602
23614 Bulk Product 138a8f23 Home & Garden $684.02 425 4.5 8 BULK-a96ce8b2
23615 Bulk Product 8846c01b Home & Garden $639.83 321 4.1 49 BULK-a2c90a75
23616 Bulk Product 49f073df Books $529.61 84 0.5 21 BULK-5d51f56f
23617 Bulk Product 6adb3320 Toys & Games $352.18 278 3.8 93 BULK-89f356ed
23618 Bulk Product 9ef6378d Home & Garden $849.23 396 0.5 94 BULK-61cb780b
23619 Bulk Product 6e6d393a Home & Garden $941.70 448 4.3 70 BULK-3f807b2e
23620 Bulk Product 34fbe875 Books $353.59 381 4.8 36 BULK-9ee07310
23621 Bulk Product 3697ae05 Electronics $163.37 379 4.1 80 BULK-33b3aa5d
23622 Bulk Product fa495061 Toys & Games $259.43 371 2.2 43 BULK-5de459c4
23623 Bulk Product b447b536 Electronics $226.65 84 2.1 1 BULK-39858a24
23624 Bulk Product 0f746f8f Toys & Games $282.23 202 2.0 78 BULK-b428517b
23625 Bulk Product 8edfeffd Electronics $987.68 316 0.8 58 BULK-38667671
23626 Bulk Product d7ed3727 Home & Garden $34.24 6 1.0 88 BULK-fba45dc6
23627 Bulk Product ffd66d74 Electronics $989.30 319 4.2 46 BULK-86d21f3d
23628 Bulk Product e306f785 Electronics $929.63 310 3.5 39 BULK-386d3d0d
23629 Bulk Product 21e26910 Home & Garden $678.52 424 4.5 72 BULK-391525c8
23630 Bulk Product e78299c8 Books $692.15 110 3.7 93 BULK-be71f1c7
23631 Bulk Product dee3cd80 Home & Garden $472.61 381 3.2 62 BULK-48871d04
23632 Bulk Product 072a22ff Books $354.30 284 1.6 34 BULK-28d7681d
23633 Bulk Product df21000c Clothing $519.16 124 4.0 18 BULK-6d89b88c
23634 Bulk Product 2104b668 Clothing $940.96 273 4.3 30 BULK-24a5d302
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