Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15310 | Bulk Product 5451e23c | Clothing | $986.06 | 330 | ★ 0.5 | 16 | BULK-5e11c5f8 |
| 15311 | Bulk Product 3acadada | Toys & Games | $217.74 | 413 | ★ 1.4 | 26 | BULK-f41a254a |
| 15312 | Bulk Product 435a07e1 | Clothing | $638.42 | 288 | ★ 1.4 | 25 | BULK-4ce1cb67 |
| 15313 | Bulk Product f551dbc9 | Electronics | $933.73 | 110 | ★ 4.9 | 32 | BULK-0dccc05b |
| 15314 | Bulk Product 079d5340 | Home & Garden | $668.94 | 398 | ★ 1.3 | 27 | BULK-24a1a0b9 |
| 15315 | Bulk Product 94388a39 | Sports & Outdoors | $683.04 | 443 | ★ 2.7 | 26 | BULK-5feb5822 |
| 15316 | Bulk Product b256ec91 | Electronics | $183.77 | 481 | ★ 4.6 | 43 | BULK-46375d2a |
| 15317 | Bulk Product e4ddeb4c | Electronics | $877.56 | 250 | ★ 4.2 | 28 | BULK-69fdeeab |
| 15318 | Bulk Product 8ab73580 | Sports & Outdoors | $956.64 | 238 | ★ 4.7 | 25 | BULK-713797e4 |
| 15319 | Bulk Product 5aa4b83a | Books | $717.96 | 146 | ★ 0.6 | 94 | BULK-c96bcfdf |
| 15320 | Bulk Product 93b93987 | Books | $191.95 | 396 | ★ 1.4 | 5 | BULK-9524e9f5 |
| 15321 | Bulk Product f78318e7 | Electronics | $255.02 | 469 | ★ 0.5 | 1 | BULK-f8a30aac |
| 15322 | Bulk Product ef7a67a2 | Home & Garden | $168.81 | 113 | ★ 3.3 | 67 | BULK-abb46aab |
| 15323 | Bulk Product 6d2d8bc9 | Books | $73.48 | 247 | ★ 3.8 | 79 | BULK-7b802454 |
| 15324 | Bulk Product 3465613f | Books | $600.53 | 363 | ★ 3.6 | 2 | BULK-2837289c |
| 15325 | Bulk Product e31b956a | Electronics | $658.87 | 404 | ★ 1.6 | 39 | BULK-4ade90dd |
| 15326 | Bulk Product af2a8cc4 | Electronics | $655.18 | 250 | ★ 0.3 | 15 | BULK-5bc228ca |
| 15327 | Bulk Product 9a979316 | Electronics | $294.17 | 246 | ★ 0.1 | 64 | BULK-6061f9a5 |
| 15328 | Bulk Product 30e6b16a | Electronics | $581.73 | 201 | ★ 4.5 | 46 | BULK-0d5c75f7 |
| 15329 | Bulk Product 366e986f | Clothing | $881.11 | 76 | ★ 2.1 | 38 | BULK-efd7e5e7 |
| 15330 | Bulk Product b88d8f18 | Toys & Games | $12.25 | 329 | ★ 1.2 | 10 | BULK-3189d183 |
| 15331 | Bulk Product 74ac8394 | Home & Garden | $821.08 | 75 | ★ 1.8 | 57 | BULK-f99343eb |
| 15332 | Bulk Product 245e964b | Clothing | $162.87 | 199 | ★ 3.2 | 73 | BULK-5ac33565 |
| 15333 | Bulk Product ab4d2362 | Electronics | $836.01 | 62 | ★ 2.4 | 95 | BULK-b6dbf8dd |
| 15334 | Bulk Product c624f364 | Electronics | $553.16 | 336 | ★ 2.1 | 85 | BULK-def7b488 |
// 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
};
}