Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5785 | Bulk Product 033cf07f | Sports & Outdoors | $378.11 | 464 | ★ 1.0 | 94 | BULK-ab040536 |
| 5786 | Bulk Product ea6ed801 | Books | $276.57 | 327 | ★ 3.4 | 61 | BULK-f62a7020 |
| 5787 | Bulk Product 385d7313 | Toys & Games | $700.78 | 271 | ★ 3.4 | 14 | BULK-6fbbee8e |
| 5788 | Bulk Product ad960107 | Electronics | $130.15 | 363 | ★ 0.4 | 92 | BULK-1d6e4fd8 |
| 5789 | Bulk Product ce4d6ab9 | Home & Garden | $212.80 | 248 | ★ 1.4 | 25 | BULK-22405300 |
| 5790 | Bulk Product 57a64487 | Books | $131.23 | 378 | ★ 4.0 | 10 | BULK-b84a1c13 |
| 5791 | Bulk Product 9653bcec | Sports & Outdoors | $254.91 | 165 | ★ 2.9 | 46 | BULK-b8fd4c1e |
| 5792 | Bulk Product a6cf9d4a | Electronics | $298.75 | 364 | ★ 1.0 | 67 | BULK-856efb12 |
| 5793 | Bulk Product 081d0670 | Books | $637.94 | 44 | ★ 1.8 | 11 | BULK-78c457e3 |
| 5794 | Bulk Product 183b17da | Home & Garden | $57.29 | 419 | ★ 3.8 | 45 | BULK-ef34cff6 |
| 5795 | Bulk Product 930397fb | Home & Garden | $877.83 | 417 | ★ 0.8 | 39 | BULK-e8d03126 |
| 5796 | Bulk Product b6cf091d | Clothing | $756.09 | 19 | ★ 4.8 | 78 | BULK-adfc1f59 |
| 5797 | Bulk Product 4eedc846 | Clothing | $570.69 | 83 | ★ 4.9 | 23 | BULK-0a3f376e |
| 5798 | Bulk Product 3e08f2e1 | Electronics | $975.78 | 99 | ★ 3.0 | 4 | BULK-ba0d3f12 |
| 5799 | Bulk Product 75ad9af3 | Electronics | $144.07 | 124 | ★ 2.5 | 30 | BULK-45b1ab55 |
| 5800 | Bulk Product 42e70ade | Clothing | $612.86 | 481 | ★ 4.1 | 34 | BULK-fded972c |
| 5801 | Bulk Product 9a5bec79 | Electronics | $182.76 | 380 | ★ 0.1 | 75 | BULK-8bdae855 |
| 5802 | Bulk Product 5d7347be | Clothing | $399.08 | 125 | ★ 1.6 | 20 | BULK-efee60cc |
| 5803 | Bulk Product ff045f78 | Sports & Outdoors | $514.87 | 234 | ★ 2.9 | 45 | BULK-757abebd |
| 5804 | Bulk Product 72ff7551 | Home & Garden | $11.83 | 143 | ★ 4.3 | 48 | BULK-ea0aaf21 |
| 5805 | Bulk Product f6981625 | Books | $647.21 | 74 | ★ 0.5 | 41 | BULK-fbe3362a |
| 5806 | Bulk Product b0dad746 | Sports & Outdoors | $447.57 | 70 | ★ 3.5 | 53 | BULK-38bba85d |
| 5807 | Bulk Product 465fcbdb | Sports & Outdoors | $767.80 | 92 | ★ 2.5 | 1 | BULK-0220bea0 |
| 5808 | Bulk Product 858e1375 | Toys & Games | $372.57 | 190 | ★ 0.5 | 12 | BULK-08d20e6c |
| 5809 | Bulk Product bf3cf540 | Sports & Outdoors | $658.72 | 286 | ★ 4.7 | 45 | BULK-ac214c72 |
// 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
};
}