Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9135 | Bulk Product 4f4e5c60 | Toys & Games | $180.97 | 482 | ★ 1.2 | 75 | BULK-1d52e900 |
| 9136 | Bulk Product 3f3d84b6 | Books | $270.23 | 71 | ★ 3.5 | 36 | BULK-c79f1cf8 |
| 9137 | Bulk Product 62986a40 | Home & Garden | $759.12 | 368 | ★ 1.5 | 1 | BULK-440c7089 |
| 9138 | Bulk Product d404d097 | Books | $936.86 | 396 | ★ 2.1 | 95 | BULK-1d5fac74 |
| 9139 | Bulk Product 0aa496f2 | Books | $444.39 | 186 | ★ 0.1 | 86 | BULK-73c305cb |
| 9140 | Bulk Product b9e9a2fc | Books | $26.59 | 180 | ★ 3.9 | 87 | BULK-eb4522fe |
| 9141 | Bulk Product cd7e4b7f | Electronics | $418.26 | 197 | ★ 4.4 | 12 | BULK-4bf6308a |
| 9142 | Bulk Product 55896883 | Electronics | $108.20 | 127 | ★ 0.7 | 67 | BULK-73963d0c |
| 9143 | Bulk Product aff38d95 | Sports & Outdoors | $620.96 | 450 | ★ 2.6 | 62 | BULK-b858ab68 |
| 9144 | Bulk Product 882f69d3 | Toys & Games | $25.65 | 363 | ★ 2.3 | 72 | BULK-4251e62c |
| 9145 | Bulk Product 0e38cb66 | Toys & Games | $547.26 | 314 | ★ 1.2 | 46 | BULK-1ddd342a |
| 9146 | Bulk Product 8e3c1e65 | Sports & Outdoors | $701.92 | 330 | ★ 4.3 | 28 | BULK-9cd819f5 |
| 9147 | Bulk Product f4b7c19d | Clothing | $132.19 | 219 | ★ 4.5 | 9 | BULK-2e76f22b |
| 9148 | Bulk Product d6f2f52d | Home & Garden | $85.96 | 476 | ★ 2.6 | 36 | BULK-f5403570 |
| 9149 | Bulk Product 21c738b9 | Home & Garden | $472.88 | 239 | ★ 4.0 | 30 | BULK-55581f2c |
| 9150 | Bulk Product 6d81bcaf | Electronics | $500.94 | 258 | ★ 0.8 | 35 | BULK-7af24353 |
| 9151 | Bulk Product e4bf8290 | Clothing | $834.96 | 50 | ★ 2.3 | 93 | BULK-14f26505 |
| 9152 | Bulk Product f76aef27 | Toys & Games | $616.39 | 209 | ★ 2.0 | 95 | BULK-5f843908 |
| 9153 | Bulk Product c513c8ba | Books | $642.21 | 192 | ★ 3.4 | 48 | BULK-e6768f27 |
| 9154 | Bulk Product 8308dd9d | Home & Garden | $253.76 | 285 | ★ 4.2 | 7 | BULK-36f5e9d0 |
| 9155 | Bulk Product b661cb99 | Sports & Outdoors | $315.69 | 182 | ★ 3.1 | 88 | BULK-d3f1ef1a |
| 9156 | Bulk Product 7d671d34 | Sports & Outdoors | $541.19 | 41 | ★ 1.8 | 93 | BULK-e668af10 |
| 9157 | Bulk Product 97156489 | Home & Garden | $646.83 | 475 | ★ 3.5 | 90 | BULK-d3ff899f |
| 9158 | Bulk Product e57d6dfe | Home & Garden | $147.71 | 63 | ★ 4.2 | 70 | BULK-c617c8e0 |
| 9159 | Bulk Product 97db9654 | Home & Garden | $508.63 | 497 | ★ 1.4 | 87 | BULK-eecb2d66 |
// 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
};
}