Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17135 | Bulk Product b7f6653f | Books | $665.37 | 164 | ★ 1.3 | 37 | BULK-126e2739 |
| 17136 | Bulk Product 81bb618e | Home & Garden | $145.03 | 10 | ★ 0.1 | 92 | BULK-b26aa736 |
| 17137 | Bulk Product 2b26e5b0 | Books | $661.73 | 355 | ★ 2.0 | 41 | BULK-fd8781c3 |
| 17138 | Bulk Product 14373589 | Electronics | $654.81 | 329 | ★ 0.6 | 37 | BULK-090a6dfc |
| 17139 | Bulk Product 2da33254 | Sports & Outdoors | $976.92 | 367 | ★ 1.7 | 70 | BULK-6ed4cf2c |
| 17140 | Bulk Product e3ef5d78 | Home & Garden | $253.19 | 295 | ★ 1.9 | 39 | BULK-5c552d85 |
| 17141 | Bulk Product 631cce5b | Books | $17.96 | 191 | ★ 2.0 | 80 | BULK-2a7c2b4f |
| 17142 | Bulk Product a6c97900 | Home & Garden | $80.06 | 355 | ★ 3.7 | 98 | BULK-1a89f974 |
| 17143 | Bulk Product 23aeb7f0 | Clothing | $972.82 | 131 | ★ 0.1 | 31 | BULK-6ff2652c |
| 17144 | Bulk Product c0577d5b | Books | $667.52 | 215 | ★ 0.2 | 58 | BULK-8dcffde4 |
| 17145 | Bulk Product f14d4fd9 | Home & Garden | $974.93 | 441 | ★ 1.3 | 31 | BULK-e85aefa4 |
| 17146 | Bulk Product 44efc14d | Electronics | $379.10 | 239 | ★ 4.4 | 84 | BULK-7210325b |
| 17147 | Bulk Product ab0f88f7 | Sports & Outdoors | $799.80 | 491 | ★ 4.1 | 95 | BULK-147f9365 |
| 17148 | Bulk Product b8bb4e00 | Clothing | $918.33 | 56 | ★ 0.2 | 18 | BULK-0a266bfb |
| 17149 | Bulk Product 694d5214 | Sports & Outdoors | $303.45 | 94 | ★ 1.8 | 44 | BULK-e88c0056 |
| 17150 | Bulk Product 34f3a62e | Toys & Games | $631.30 | 370 | ★ 3.7 | 43 | BULK-56e429ec |
| 17151 | Bulk Product 56748633 | Sports & Outdoors | $231.79 | 276 | ★ 0.3 | 22 | BULK-5ec40e64 |
| 17152 | Bulk Product 6e991de1 | Clothing | $646.68 | 166 | ★ 1.4 | 57 | BULK-9c8e3491 |
| 17153 | Bulk Product 8cf0f876 | Toys & Games | $518.88 | 77 | ★ 0.7 | 70 | BULK-4f7ae5f5 |
| 17154 | Bulk Product 6329fc86 | Clothing | $29.00 | 1 | ★ 1.2 | 66 | BULK-c4b1e5dc |
| 17155 | Bulk Product 5c9c37cc | Books | $855.89 | 254 | ★ 3.5 | 2 | BULK-ac1b042a |
| 17156 | Bulk Product b3b33633 | Toys & Games | $173.44 | 193 | ★ 3.6 | 63 | BULK-81716ccb |
| 17157 | Bulk Product 308793fa | Books | $13.25 | 375 | ★ 4.3 | 54 | BULK-46a78144 |
| 17158 | Bulk Product 082b12ae | Clothing | $330.92 | 391 | ★ 0.6 | 13 | BULK-3fccd550 |
| 17159 | Bulk Product c4aa64b2 | Sports & Outdoors | $546.93 | 0 | ★ 4.6 | 87 | BULK-5385649b |
// 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
};
}