Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5360 | Bulk Product 5a8467c8 | Toys & Games | $120.33 | 475 | ★ 3.1 | 87 | BULK-0f1f49f8 |
| 5361 | Bulk Product 7208333f | Clothing | $290.35 | 144 | ★ 1.9 | 78 | BULK-63ab5c26 |
| 5362 | Bulk Product b3ba2632 | Toys & Games | $608.64 | 238 | ★ 3.0 | 56 | BULK-4062b9ef |
| 5363 | Bulk Product 1ca44b8a | Sports & Outdoors | $115.62 | 329 | ★ 1.7 | 7 | BULK-28b40d67 |
| 5364 | Bulk Product 1097ba89 | Sports & Outdoors | $742.51 | 362 | ★ 4.7 | 86 | BULK-c168235d |
| 5365 | Bulk Product 5e1d6156 | Home & Garden | $18.73 | 103 | ★ 3.8 | 79 | BULK-84e33b6c |
| 5366 | Bulk Product edcff130 | Electronics | $774.12 | 80 | ★ 3.2 | 57 | BULK-9e993fdf |
| 5367 | Bulk Product 85e6e3e4 | Sports & Outdoors | $407.53 | 105 | ★ 2.7 | 61 | BULK-e5de7fe9 |
| 5368 | Bulk Product e53c33fc | Books | $528.31 | 306 | ★ 0.8 | 43 | BULK-49a8187d |
| 5369 | Bulk Product b29f9721 | Home & Garden | $134.13 | 169 | ★ 0.6 | 13 | BULK-48e5a268 |
| 5370 | Bulk Product 21869f2a | Clothing | $224.20 | 485 | ★ 1.8 | 11 | BULK-d84e075b |
| 5371 | Bulk Product 8cd9d8b3 | Books | $556.45 | 322 | ★ 4.8 | 39 | BULK-413de560 |
| 5372 | Bulk Product 264c2bf8 | Toys & Games | $424.23 | 437 | ★ 2.3 | 98 | BULK-0f547d8e |
| 5373 | Bulk Product 71899967 | Toys & Games | $515.93 | 185 | ★ 0.6 | 23 | BULK-e1940c1e |
| 5374 | Bulk Product 39a67ec0 | Toys & Games | $629.00 | 346 | ★ 1.4 | 18 | BULK-93d4c3ef |
| 5375 | Bulk Product a097f958 | Clothing | $137.42 | 188 | ★ 1.3 | 48 | BULK-fdeb8508 |
| 5376 | Bulk Product af75b66f | Home & Garden | $106.89 | 99 | ★ 3.7 | 75 | BULK-e35a8917 |
| 5377 | Bulk Product f850eac3 | Clothing | $133.73 | 53 | ★ 3.7 | 80 | BULK-5cb4b2a4 |
| 5378 | Bulk Product 0d79bc81 | Home & Garden | $924.89 | 304 | ★ 0.4 | 72 | BULK-7e55d8fe |
| 5379 | Bulk Product 3cbe82ec | Toys & Games | $657.60 | 265 | ★ 1.1 | 27 | BULK-0bc83e78 |
| 5380 | Bulk Product accc8499 | Sports & Outdoors | $53.53 | 483 | ★ 4.5 | 70 | BULK-5d2bfbda |
| 5381 | Bulk Product 73bf72d2 | Books | $133.33 | 389 | ★ 0.2 | 82 | BULK-f338d418 |
| 5382 | Bulk Product 3a1876e8 | Books | $152.68 | 203 | ★ 1.7 | 68 | BULK-a2c6294e |
| 5383 | Bulk Product 5013d80c | Sports & Outdoors | $293.93 | 79 | ★ 0.6 | 41 | BULK-91b9b53a |
| 5384 | Bulk Product 98742e59 | Books | $672.42 | 201 | ★ 1.1 | 59 | BULK-6d5aca21 |
// 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
};
}