Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8410 | Bulk Product 61773802 | Home & Garden | $342.70 | 384 | ★ 2.9 | 59 | BULK-559d307a |
| 8411 | Bulk Product f7c1b5df | Home & Garden | $831.39 | 255 | ★ 1.4 | 43 | BULK-cc7b9a44 |
| 8412 | Bulk Product 41f173c2 | Books | $391.59 | 17 | ★ 1.8 | 58 | BULK-b42a8318 |
| 8413 | Bulk Product f5c535a0 | Home & Garden | $924.38 | 350 | ★ 4.7 | 30 | BULK-67a22937 |
| 8414 | Bulk Product 97aca415 | Clothing | $160.35 | 303 | ★ 1.1 | 16 | BULK-36ca6bbf |
| 8415 | Bulk Product 7f41e7f0 | Books | $554.70 | 77 | ★ 3.9 | 61 | BULK-5bb2bda4 |
| 8416 | Bulk Product 0350370a | Sports & Outdoors | $168.16 | 455 | ★ 3.6 | 89 | BULK-1ce5f40c |
| 8417 | Bulk Product 395691f9 | Clothing | $352.11 | 448 | ★ 3.5 | 40 | BULK-101f753f |
| 8418 | Bulk Product e15f2892 | Sports & Outdoors | $543.12 | 28 | ★ 0.7 | 61 | BULK-1e7403b4 |
| 8419 | Bulk Product eb5e4b0b | Toys & Games | $283.13 | 180 | ★ 1.2 | 87 | BULK-0ce62ac8 |
| 8420 | Bulk Product e78a5505 | Clothing | $26.23 | 290 | ★ 0.5 | 85 | BULK-8905ac61 |
| 8421 | Bulk Product ab20b64f | Books | $657.19 | 359 | ★ 4.8 | 98 | BULK-f81846a3 |
| 8422 | Bulk Product cc56c4bf | Home & Garden | $917.17 | 427 | ★ 0.8 | 5 | BULK-916a5c04 |
| 8423 | Bulk Product f71ebf6f | Sports & Outdoors | $275.21 | 76 | ★ 0.6 | 55 | BULK-608e93a8 |
| 8424 | Bulk Product e40d7790 | Books | $582.89 | 323 | ★ 0.9 | 5 | BULK-8318af98 |
| 8425 | Bulk Product 01e5149b | Toys & Games | $798.64 | 452 | ★ 1.1 | 98 | BULK-5188d87b |
| 8426 | Bulk Product 93ec752d | Clothing | $930.91 | 194 | ★ 4.8 | 86 | BULK-2e132bfc |
| 8427 | Bulk Product 5bb7bd2b | Sports & Outdoors | $944.99 | 393 | ★ 4.2 | 0 | BULK-9c1c1739 |
| 8428 | Bulk Product e7f9c33c | Electronics | $436.88 | 389 | ★ 1.0 | 20 | BULK-6e5cfbaa |
| 8429 | Bulk Product b069d7a8 | Home & Garden | $887.01 | 430 | ★ 2.6 | 16 | BULK-88c9437c |
| 8430 | Bulk Product c389a9b1 | Home & Garden | $419.96 | 345 | ★ 0.9 | 60 | BULK-0a7ce3c4 |
| 8431 | Bulk Product 4968588e | Clothing | $748.76 | 325 | ★ 0.1 | 39 | BULK-5488772c |
| 8432 | Bulk Product 39de1d58 | Sports & Outdoors | $798.54 | 132 | ★ 0.9 | 31 | BULK-03909a5b |
| 8433 | Bulk Product 059de47b | Toys & Games | $239.18 | 226 | ★ 2.4 | 56 | BULK-98e6ef30 |
| 8434 | Bulk Product 15218325 | Toys & Games | $946.10 | 105 | ★ 1.1 | 93 | BULK-f32f9529 |
// 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
};
}