Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

642 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 642 Results Showing 16026 - 16050 of 24441

ID Name Category Price Stock Rating Reviews SKU
16585 Bulk Product 31b5d923 Electronics $904.25 10 1.0 38 BULK-cc2d8155
16586 Bulk Product 60766f43 Sports & Outdoors $642.35 320 2.6 86 BULK-412da98d
16587 Bulk Product 934eaec9 Toys & Games $992.73 466 1.7 41 BULK-255fc703
16588 Bulk Product 5c445652 Books $482.25 426 4.7 53 BULK-b49055ce
16589 Bulk Product e9ad6757 Sports & Outdoors $682.98 141 4.9 90 BULK-99f19319
16590 Bulk Product d5e4611f Toys & Games $943.73 90 2.2 85 BULK-b4170d36
16591 Bulk Product c4c23d26 Home & Garden $238.10 52 2.1 66 BULK-01595cdb
16592 Bulk Product 0c266880 Books $87.15 328 1.2 46 BULK-1dd00d38
16593 Bulk Product bfa1e259 Sports & Outdoors $995.96 396 4.7 3 BULK-cc7de934
16594 Bulk Product 132d2d92 Toys & Games $55.87 420 2.2 68 BULK-89cc211d
16595 Bulk Product 3015e940 Toys & Games $923.61 208 2.6 56 BULK-360001f9
16596 Bulk Product 294565a1 Toys & Games $558.63 310 0.5 22 BULK-6d6a70ec
16597 Bulk Product fc0c8b43 Home & Garden $634.65 275 0.0 37 BULK-d28b114c
16598 Bulk Product 2e49560c Home & Garden $45.38 456 0.4 46 BULK-270a6c80
16599 Bulk Product 6d0881b8 Books $24.75 470 0.6 6 BULK-7fe34f6a
16600 Bulk Product c400e3f3 Electronics $973.42 408 3.6 23 BULK-73c12cc2
16601 Bulk Product 240dc876 Clothing $498.12 383 3.1 92 BULK-ae9ea3ac
16602 Bulk Product a3047f41 Sports & Outdoors $534.98 381 0.6 85 BULK-22612e56
16603 Bulk Product 784aa040 Toys & Games $126.01 116 4.6 8 BULK-07c98e3d
16604 Bulk Product e3e18010 Electronics $442.94 133 3.3 46 BULK-8d0c10d6
16605 Bulk Product e3c17260 Toys & Games $903.44 282 4.0 70 BULK-67598059
16606 Bulk Product 24bc2205 Books $931.76 497 1.1 81 BULK-204d4105
16607 Bulk Product 67fdf6c7 Books $861.88 152 0.8 55 BULK-8fdd01d9
16608 Bulk Product 60e35a98 Books $803.13 407 3.5 89 BULK-042285c1
16609 Bulk Product 78bf1e49 Home & Garden $30.08 163 0.6 35 BULK-45b7a88b
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