Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 14735 | Bulk Product 1ffb165d | Electronics | $334.53 | 160 | ★ 1.8 | 8 | BULK-2c57dded |
| 14736 | Bulk Product 239a9f9f | Books | $148.96 | 285 | ★ 4.8 | 69 | BULK-4fb21a8e |
| 14737 | Bulk Product 150661eb | Sports & Outdoors | $617.16 | 422 | ★ 2.3 | 69 | BULK-4591513e |
| 14738 | Bulk Product db1ade42 | Clothing | $450.56 | 490 | ★ 1.8 | 66 | BULK-e49dfc70 |
| 14739 | Bulk Product 9cfa5bd6 | Toys & Games | $581.32 | 261 | ★ 4.1 | 3 | BULK-0295ccae |
| 14740 | Bulk Product 3e2b2b1b | Books | $283.12 | 106 | ★ 3.8 | 58 | BULK-013149d8 |
| 14741 | Bulk Product e6363182 | Sports & Outdoors | $690.56 | 83 | ★ 2.2 | 56 | BULK-ae8d7fa2 |
| 14742 | Bulk Product dc04f688 | Clothing | $551.26 | 494 | ★ 4.5 | 58 | BULK-0a8920dc |
| 14743 | Bulk Product 9c419a30 | Books | $738.91 | 132 | ★ 2.5 | 88 | BULK-4fa63b3c |
| 14744 | Bulk Product 39db7a86 | Toys & Games | $112.31 | 392 | ★ 4.0 | 24 | BULK-5a7e3522 |
| 14745 | Bulk Product 61fabbae | Toys & Games | $793.75 | 421 | ★ 2.3 | 58 | BULK-71e2bb02 |
| 14746 | Bulk Product 2d2b833e | Electronics | $324.55 | 430 | ★ 2.5 | 21 | BULK-82762861 |
| 14747 | Bulk Product ec97a4b4 | Electronics | $976.95 | 280 | ★ 3.0 | 16 | BULK-678caf8f |
| 14748 | Bulk Product 3621691b | Electronics | $740.47 | 29 | ★ 3.9 | 91 | BULK-0d53ccfa |
| 14749 | Bulk Product 013baa00 | Toys & Games | $704.00 | 89 | ★ 2.8 | 74 | BULK-c6f2fc3a |
| 14750 | Bulk Product 482ace23 | Clothing | $833.71 | 443 | ★ 2.8 | 98 | BULK-81d7c2c0 |
| 14751 | Bulk Product d6bbd130 | Electronics | $419.66 | 290 | ★ 3.0 | 99 | BULK-3e511aee |
| 14752 | Bulk Product 58a067a0 | Clothing | $597.71 | 179 | ★ 3.6 | 27 | BULK-c2aacc04 |
| 14753 | Bulk Product 113f59aa | Electronics | $585.54 | 209 | ★ 4.3 | 56 | BULK-031f62dc |
| 14754 | Bulk Product b29447c3 | Books | $526.78 | 242 | ★ 2.4 | 53 | BULK-1245ef65 |
| 14755 | Bulk Product 10d19545 | Sports & Outdoors | $908.08 | 156 | ★ 3.9 | 67 | BULK-8c4eb3bf |
| 14756 | Bulk Product 4bbe25e1 | Toys & Games | $68.04 | 389 | ★ 1.0 | 28 | BULK-0b348978 |
| 14757 | Bulk Product d1033c55 | Electronics | $174.44 | 293 | ★ 3.4 | 56 | BULK-72a373bd |
| 14758 | Bulk Product 5f745593 | Electronics | $51.64 | 413 | ★ 3.2 | 42 | BULK-f75181cd |
| 14759 | Bulk Product 1197bf6f | Toys & Games | $245.75 | 139 | ★ 2.2 | 91 | BULK-687c320a |
// 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
};
}