Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15485 | Bulk Product e57dd48e | Electronics | $147.32 | 368 | ★ 5.0 | 99 | BULK-7be0d2e6 |
| 15486 | Bulk Product 93cbeadc | Electronics | $19.86 | 129 | ★ 1.7 | 1 | BULK-afd7e0cd |
| 15487 | Bulk Product 819fa533 | Electronics | $513.70 | 13 | ★ 2.1 | 76 | BULK-43ff9fd8 |
| 15488 | Bulk Product 36505342 | Books | $478.38 | 427 | ★ 3.2 | 49 | BULK-7759624b |
| 15489 | Bulk Product cfddd8d2 | Books | $462.70 | 413 | ★ 4.9 | 77 | BULK-ae576ed1 |
| 15490 | Bulk Product 856c95e2 | Clothing | $829.84 | 479 | ★ 2.6 | 66 | BULK-3f8f11a0 |
| 15491 | Bulk Product 30e37ed5 | Sports & Outdoors | $20.17 | 453 | ★ 0.6 | 25 | BULK-38e3d70a |
| 15492 | Bulk Product 1b807a1d | Books | $74.47 | 113 | ★ 1.2 | 6 | BULK-8cf5f4c0 |
| 15493 | Bulk Product 7f8774ab | Toys & Games | $96.69 | 453 | ★ 2.7 | 15 | BULK-e15b0842 |
| 15494 | Bulk Product 5ed42c2a | Electronics | $381.70 | 144 | ★ 4.0 | 54 | BULK-ba0d949a |
| 15495 | Bulk Product 7761707a | Home & Garden | $910.63 | 150 | ★ 2.8 | 72 | BULK-41c02e3d |
| 15496 | Bulk Product c325a66a | Books | $448.16 | 261 | ★ 1.9 | 92 | BULK-85856dbc |
| 15497 | Bulk Product e09a973d | Toys & Games | $587.49 | 183 | ★ 2.7 | 28 | BULK-fa1cb99a |
| 15498 | Bulk Product 6a09a855 | Toys & Games | $763.74 | 10 | ★ 4.7 | 88 | BULK-2e11827e |
| 15499 | Bulk Product fd0071ad | Books | $210.74 | 174 | ★ 1.7 | 72 | BULK-4e648bb8 |
| 15500 | Bulk Product 39e0ba82 | Sports & Outdoors | $189.76 | 50 | ★ 4.5 | 50 | BULK-82422e4c |
| 15501 | Bulk Product 7ce4cc43 | Sports & Outdoors | $324.85 | 49 | ★ 3.4 | 48 | BULK-f8a193bf |
| 15502 | Bulk Product 6ef6dc30 | Sports & Outdoors | $888.36 | 25 | ★ 4.5 | 43 | BULK-19222dbb |
| 15503 | Bulk Product 63f57d82 | Books | $975.49 | 418 | ★ 1.3 | 45 | BULK-1e086ab8 |
| 15504 | Bulk Product 5c118001 | Clothing | $418.24 | 197 | ★ 2.3 | 25 | BULK-143cf496 |
| 15505 | Bulk Product 527361fe | Sports & Outdoors | $683.55 | 336 | ★ 1.3 | 4 | BULK-c89b3f06 |
| 15506 | Bulk Product 16d7bc45 | Clothing | $297.11 | 198 | ★ 0.4 | 5 | BULK-4107138e |
| 15507 | Bulk Product df1d7970 | Books | $556.31 | 23 | ★ 1.2 | 29 | BULK-b0c0dd41 |
| 15508 | Bulk Product 348251a8 | Electronics | $329.99 | 417 | ★ 0.4 | 89 | BULK-3c013db6 |
| 15509 | Bulk Product 400e7b56 | Clothing | $530.35 | 429 | ★ 3.6 | 19 | BULK-8043c602 |
// 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
};
}