Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 19410 | Bulk Product 20e58f26 | Books | $746.56 | 499 | ★ 3.4 | 2 | BULK-477b83fe |
| 19411 | Bulk Product 15fa61b4 | Books | $850.94 | 347 | ★ 0.9 | 38 | BULK-fb4a4bc4 |
| 19412 | Bulk Product adc15006 | Sports & Outdoors | $757.78 | 386 | ★ 5.0 | 93 | BULK-3137aa33 |
| 19413 | Bulk Product c5f41cd5 | Sports & Outdoors | $436.54 | 283 | ★ 1.7 | 77 | BULK-ce44f618 |
| 19414 | Bulk Product 3a725879 | Electronics | $804.62 | 415 | ★ 0.2 | 18 | BULK-460ee21f |
| 19415 | Bulk Product 15cd0e9d | Home & Garden | $866.93 | 232 | ★ 0.5 | 93 | BULK-7751214f |
| 19416 | Bulk Product 93b0c0b6 | Home & Garden | $383.33 | 190 | ★ 0.7 | 90 | BULK-6d252545 |
| 19417 | Bulk Product c602f787 | Sports & Outdoors | $783.95 | 295 | ★ 2.9 | 71 | BULK-103375ba |
| 19418 | Bulk Product 0fea1d20 | Toys & Games | $877.99 | 442 | ★ 0.0 | 7 | BULK-30219e4d |
| 19419 | Bulk Product ab901e6b | Books | $213.08 | 119 | ★ 1.7 | 45 | BULK-f90c6dd4 |
| 19420 | Bulk Product 0d88f245 | Clothing | $257.92 | 344 | ★ 4.8 | 13 | BULK-16dcb870 |
| 19421 | Bulk Product 2bc1617d | Clothing | $988.84 | 352 | ★ 3.6 | 78 | BULK-a3edd2f7 |
| 19422 | Bulk Product 9299da50 | Clothing | $390.28 | 145 | ★ 0.4 | 61 | BULK-6345bd9f |
| 19423 | Bulk Product 2f42b4f8 | Electronics | $142.81 | 249 | ★ 4.1 | 71 | BULK-923e9fd1 |
| 19424 | Bulk Product d55ef77f | Toys & Games | $789.73 | 56 | ★ 2.6 | 66 | BULK-3a3e7917 |
| 19425 | Bulk Product 0a6557af | Home & Garden | $823.58 | 477 | ★ 4.4 | 86 | BULK-b267578f |
| 19426 | Bulk Product ffa9e04e | Clothing | $906.32 | 309 | ★ 2.8 | 42 | BULK-300ead48 |
| 19427 | Bulk Product e3fda901 | Toys & Games | $74.68 | 305 | ★ 1.1 | 32 | BULK-b9bbb22d |
| 19428 | Bulk Product e1bdf499 | Toys & Games | $60.11 | 267 | ★ 4.3 | 58 | BULK-cf03d9c7 |
| 19429 | Bulk Product 7dad3851 | Home & Garden | $660.22 | 24 | ★ 1.0 | 70 | BULK-1a653131 |
| 19430 | Bulk Product 960c77fd | Books | $349.81 | 354 | ★ 0.4 | 18 | BULK-2675ec1c |
| 19431 | Bulk Product 46812038 | Books | $100.48 | 457 | ★ 1.6 | 34 | BULK-c50de280 |
| 19432 | Bulk Product b671f9aa | Sports & Outdoors | $647.33 | 279 | ★ 1.3 | 53 | BULK-ca262a76 |
| 19433 | Bulk Product 33cebf62 | Books | $16.44 | 176 | ★ 3.0 | 32 | BULK-78223256 |
| 19434 | Bulk Product 2beba750 | Sports & Outdoors | $879.59 | 433 | ★ 4.1 | 26 | BULK-c86ce204 |
// 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
};
}