Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 16360 | Bulk Product bd765e5b | Books | $738.80 | 312 | ★ 3.7 | 22 | BULK-bddfd4eb |
| 16361 | Bulk Product ff1c8477 | Books | $842.19 | 150 | ★ 0.1 | 21 | BULK-4328b392 |
| 16362 | Bulk Product ddf94c62 | Books | $369.44 | 459 | ★ 0.4 | 33 | BULK-cd2051dc |
| 16363 | Bulk Product 1b10c485 | Home & Garden | $802.85 | 210 | ★ 3.7 | 76 | BULK-eaba7408 |
| 16364 | Bulk Product 594a9827 | Toys & Games | $35.81 | 255 | ★ 0.4 | 39 | BULK-a4c7bd77 |
| 16365 | Bulk Product c871ef78 | Electronics | $680.77 | 253 | ★ 2.1 | 81 | BULK-729faa31 |
| 16366 | Bulk Product 66dbc0ad | Electronics | $549.42 | 127 | ★ 1.7 | 38 | BULK-d7603e7d |
| 16367 | Bulk Product 58b47868 | Home & Garden | $832.92 | 368 | ★ 1.4 | 78 | BULK-b034113d |
| 16368 | Bulk Product fd888387 | Electronics | $703.08 | 1 | ★ 4.1 | 17 | BULK-c7f5aad8 |
| 16369 | Bulk Product 0a10ae39 | Toys & Games | $853.01 | 200 | ★ 1.2 | 0 | BULK-6ed202e7 |
| 16370 | Bulk Product f8313227 | Electronics | $882.84 | 337 | ★ 4.1 | 64 | BULK-8b7a94a7 |
| 16371 | Bulk Product 2d6ef958 | Sports & Outdoors | $718.53 | 422 | ★ 1.3 | 74 | BULK-aa12007e |
| 16372 | Bulk Product bfdc8f3f | Clothing | $824.60 | 303 | ★ 1.9 | 7 | BULK-e97dfaca |
| 16373 | Bulk Product b60b77a5 | Clothing | $38.37 | 36 | ★ 3.4 | 88 | BULK-b27b2278 |
| 16374 | Bulk Product e4793c74 | Sports & Outdoors | $797.65 | 438 | ★ 2.5 | 42 | BULK-c150260b |
| 16375 | Bulk Product 03c8522d | Toys & Games | $986.53 | 59 | ★ 2.2 | 4 | BULK-ec6519df |
| 16376 | Bulk Product 0e5ba4ce | Sports & Outdoors | $814.38 | 80 | ★ 2.7 | 60 | BULK-0db2310e |
| 16377 | Bulk Product 84b81119 | Sports & Outdoors | $880.13 | 347 | ★ 0.4 | 15 | BULK-5e4c5f27 |
| 16378 | Bulk Product c32b9a9b | Home & Garden | $730.70 | 480 | ★ 1.4 | 34 | BULK-6a6998fa |
| 16379 | Bulk Product b98e3273 | Electronics | $511.48 | 415 | ★ 5.0 | 14 | BULK-efb6e462 |
| 16380 | Bulk Product 08cf9691 | Home & Garden | $503.92 | 181 | ★ 1.6 | 15 | BULK-af9aaa4f |
| 16381 | Bulk Product 15ae395f | Toys & Games | $153.11 | 10 | ★ 2.7 | 80 | BULK-cf0d1bdd |
| 16382 | Bulk Product 2c187323 | Books | $545.74 | 451 | ★ 1.8 | 87 | BULK-3e7ee5ef |
| 16383 | Bulk Product 16d8705e | Sports & Outdoors | $757.87 | 53 | ★ 4.8 | 70 | BULK-b2f96454 |
| 16384 | Bulk Product 64974079 | Electronics | $412.50 | 466 | ★ 2.1 | 21 | BULK-948b33f6 |
// 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
};
}