Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 20360 | Bulk Product 4198bc98 | Clothing | $831.65 | 140 | ★ 3.1 | 10 | BULK-9240c0ad |
| 20361 | Bulk Product 57f2f12a | Home & Garden | $439.45 | 128 | ★ 3.4 | 58 | BULK-91287ada |
| 20362 | Bulk Product ea78440b | Sports & Outdoors | $408.54 | 248 | ★ 2.3 | 84 | BULK-7a77c093 |
| 20363 | Bulk Product e593d1ad | Toys & Games | $163.26 | 449 | ★ 0.4 | 68 | BULK-ee9ffef3 |
| 20364 | Bulk Product 2602ceef | Sports & Outdoors | $697.04 | 169 | ★ 3.4 | 36 | BULK-761afc58 |
| 20365 | Bulk Product ecd5327a | Sports & Outdoors | $923.62 | 259 | ★ 4.0 | 74 | BULK-b52ed7a9 |
| 20366 | Bulk Product f73d459d | Electronics | $650.31 | 394 | ★ 4.9 | 11 | BULK-48d30073 |
| 20367 | Bulk Product c7f210eb | Electronics | $332.24 | 221 | ★ 1.3 | 19 | BULK-b39082fa |
| 20368 | Bulk Product 5fe7560e | Sports & Outdoors | $562.35 | 227 | ★ 0.8 | 72 | BULK-56004986 |
| 20369 | Bulk Product c55bfc5b | Clothing | $474.64 | 15 | ★ 3.9 | 13 | BULK-61702643 |
| 20370 | Bulk Product c4aeef3b | Toys & Games | $511.06 | 113 | ★ 0.1 | 87 | BULK-8e9581a3 |
| 20371 | Bulk Product ded54f7f | Home & Garden | $625.65 | 76 | ★ 3.6 | 67 | BULK-a09d93d9 |
| 20372 | Bulk Product ee59100b | Toys & Games | $157.18 | 453 | ★ 4.5 | 97 | BULK-7c033e23 |
| 20373 | Bulk Product 00a15f37 | Sports & Outdoors | $768.99 | 483 | ★ 3.5 | 10 | BULK-b4bd647b |
| 20374 | Bulk Product 198e300e | Home & Garden | $529.11 | 332 | ★ 4.3 | 84 | BULK-cfa9cb27 |
| 20375 | Bulk Product e830fb32 | Sports & Outdoors | $874.44 | 483 | ★ 3.7 | 5 | BULK-dffc10c0 |
| 20376 | Bulk Product 3e679be4 | Home & Garden | $492.48 | 266 | ★ 4.6 | 84 | BULK-b9b05fe6 |
| 20377 | Bulk Product 879beef3 | Sports & Outdoors | $497.54 | 154 | ★ 1.7 | 10 | BULK-210789df |
| 20378 | Bulk Product 9da3098a | Clothing | $251.81 | 234 | ★ 1.4 | 0 | BULK-539386e1 |
| 20379 | Bulk Product 918e1f42 | Clothing | $978.39 | 233 | ★ 0.3 | 95 | BULK-2c9e619a |
| 20380 | Bulk Product b2903e8a | Books | $867.44 | 82 | ★ 1.2 | 11 | BULK-b622ca50 |
| 20381 | Bulk Product 099a2719 | Toys & Games | $660.22 | 313 | ★ 4.3 | 20 | BULK-021f36c2 |
| 20382 | Bulk Product 32c18845 | Electronics | $98.39 | 349 | ★ 1.8 | 9 | BULK-45bdc8b8 |
| 20383 | Bulk Product 45989c89 | Books | $326.88 | 343 | ★ 4.3 | 33 | BULK-57b726f2 |
| 20384 | Bulk Product 0de2f23a | Sports & Outdoors | $440.71 | 334 | ★ 4.7 | 46 | BULK-d44cb0d1 |
// 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
};
}