Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

54 ms

Page Size

25

Current Page

329 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 329 Results Showing 8201 - 8225 of 24441

ID Name Category Price Stock Rating Reviews SKU
8760 Bulk Product 09a21377 Books $205.91 369 4.2 50 BULK-42630311
8761 Bulk Product ab2a66a5 Electronics $21.33 24 4.1 43 BULK-cf25886c
8762 Bulk Product d6efb72b Clothing $149.84 74 2.8 88 BULK-df859491
8763 Bulk Product 8afa34df Electronics $662.38 56 4.4 85 BULK-bb72ea8b
8764 Bulk Product b101bec4 Toys & Games $969.21 177 3.6 83 BULK-e036c09d
8765 Bulk Product 69636c54 Electronics $120.14 88 1.7 16 BULK-9df2b9c6
8766 Bulk Product 87e0d9b8 Books $906.53 285 2.8 60 BULK-b9d19b9f
8767 Bulk Product 59b5f505 Home & Garden $905.28 347 2.5 47 BULK-407b9487
8768 Bulk Product a6c56bf5 Clothing $110.23 246 3.3 8 BULK-dea5215e
8769 Bulk Product 64c9f16b Clothing $445.03 24 0.7 63 BULK-6687ef95
8770 Bulk Product b8037668 Sports & Outdoors $310.14 185 4.9 56 BULK-15fc86ce
8771 Bulk Product 76aa87eb Books $808.11 139 2.0 36 BULK-ac33b23c
8772 Bulk Product a25de683 Electronics $689.73 129 4.2 95 BULK-e793168d
8773 Bulk Product 535e9968 Sports & Outdoors $284.61 87 0.0 80 BULK-6d4c7270
8774 Bulk Product d9b267c7 Electronics $49.58 204 3.4 87 BULK-5e631cc8
8775 Bulk Product 9c430dc6 Toys & Games $267.18 468 1.2 71 BULK-ddcd086a
8776 Bulk Product 8a8ef3c1 Toys & Games $676.92 311 2.1 70 BULK-6d79d0dd
8777 Bulk Product c7ec0008 Toys & Games $833.71 153 0.8 5 BULK-8d68b281
8778 Bulk Product d962e4ec Books $787.11 104 2.8 27 BULK-5a08a7e2
8779 Bulk Product 4cf1be9b Sports & Outdoors $210.71 6 2.2 2 BULK-fd262327
8780 Bulk Product 5e78d339 Electronics $111.14 150 0.6 16 BULK-d52d4d56
8781 Bulk Product 776e1029 Electronics $133.11 137 3.0 16 BULK-c2293d2e
8782 Bulk Product 1d0b2434 Clothing $332.80 255 3.6 28 BULK-284e349a
8783 Bulk Product f7a00721 Home & Garden $147.93 490 3.5 91 BULK-e2707cc4
8784 Bulk Product b7c042f1 Home & Garden $508.23 65 4.1 34 BULK-7dbf8d98
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