Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15460 | Bulk Product 2054d12d | Sports & Outdoors | $697.32 | 467 | ★ 4.6 | 7 | BULK-95875094 |
| 15461 | Bulk Product 46c72da9 | Clothing | $890.19 | 221 | ★ 3.5 | 41 | BULK-45f77004 |
| 15462 | Bulk Product 7f45cbf6 | Electronics | $200.69 | 314 | ★ 1.1 | 92 | BULK-a18fd470 |
| 15463 | Bulk Product 83ebdd1f | Electronics | $740.15 | 100 | ★ 1.2 | 75 | BULK-d5d75a3b |
| 15464 | Bulk Product 5acdcdee | Clothing | $325.58 | 181 | ★ 4.3 | 97 | BULK-fa458dff |
| 15465 | Bulk Product 4c6ee5af | Books | $776.18 | 313 | ★ 4.4 | 56 | BULK-8f09d2a2 |
| 15466 | Bulk Product f0f868b6 | Electronics | $432.49 | 477 | ★ 3.5 | 55 | BULK-290b99c4 |
| 15467 | Bulk Product 848a0ab8 | Sports & Outdoors | $578.38 | 145 | ★ 1.3 | 75 | BULK-0628bbcc |
| 15468 | Bulk Product ae338767 | Electronics | $498.18 | 140 | ★ 0.7 | 20 | BULK-7e869da2 |
| 15469 | Bulk Product ddcb6717 | Toys & Games | $455.38 | 143 | ★ 2.1 | 16 | BULK-f84e9865 |
| 15470 | Bulk Product 4cdfb0d4 | Electronics | $320.42 | 66 | ★ 1.7 | 90 | BULK-bb14deab |
| 15471 | Bulk Product 2e2b0849 | Clothing | $746.56 | 39 | ★ 4.9 | 45 | BULK-f9e0d5ce |
| 15472 | Bulk Product b82f32cf | Toys & Games | $929.69 | 490 | ★ 1.1 | 8 | BULK-ca14f056 |
| 15473 | Bulk Product cb18dacd | Clothing | $590.42 | 160 | ★ 5.0 | 61 | BULK-3e53d12a |
| 15474 | Bulk Product b7667186 | Clothing | $673.69 | 254 | ★ 1.5 | 99 | BULK-19090e02 |
| 15475 | Bulk Product 84f2bfb1 | Toys & Games | $140.85 | 324 | ★ 2.5 | 5 | BULK-8c25c044 |
| 15476 | Bulk Product 9d601469 | Home & Garden | $270.47 | 271 | ★ 0.6 | 1 | BULK-bd1737f8 |
| 15477 | Bulk Product 55f936a1 | Clothing | $467.38 | 81 | ★ 1.7 | 66 | BULK-e84790f9 |
| 15478 | Bulk Product 8bdd988e | Toys & Games | $923.15 | 21 | ★ 0.7 | 80 | BULK-7cded128 |
| 15479 | Bulk Product 8aa6b520 | Clothing | $161.33 | 209 | ★ 2.6 | 58 | BULK-f6d52656 |
| 15480 | Bulk Product 76a2c2d2 | Sports & Outdoors | $71.87 | 279 | ★ 0.4 | 96 | BULK-cf0e52c2 |
| 15481 | Bulk Product fafa4662 | Books | $104.74 | 434 | ★ 1.9 | 47 | BULK-9636add1 |
| 15482 | Bulk Product a1dba939 | Home & Garden | $525.64 | 90 | ★ 3.0 | 34 | BULK-e7d47b59 |
| 15483 | Bulk Product 0c7c89de | Electronics | $811.41 | 431 | ★ 1.5 | 11 | BULK-3b206cd5 |
| 15484 | Bulk Product 010a1fe8 | Books | $102.87 | 335 | ★ 2.5 | 97 | BULK-bcc75716 |
| 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
};
}