Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 12760 | Bulk Product cddb7f28 | Sports & Outdoors | $971.17 | 210 | ★ 3.1 | 36 | BULK-b0b37dec |
| 12761 | Bulk Product 2857e3d3 | Sports & Outdoors | $817.26 | 148 | ★ 1.6 | 73 | BULK-865033ed |
| 12762 | Bulk Product 2896ffc0 | Toys & Games | $536.87 | 83 | ★ 4.2 | 33 | BULK-87ed7052 |
| 12763 | Bulk Product 487b0a2e | Toys & Games | $235.31 | 390 | ★ 0.7 | 11 | BULK-bb33be5e |
| 12764 | Bulk Product 8670c6a1 | Books | $781.94 | 380 | ★ 3.0 | 73 | BULK-c2450553 |
| 12765 | Bulk Product f3ecbb78 | Sports & Outdoors | $717.88 | 72 | ★ 1.3 | 11 | BULK-e43cc7be |
| 12766 | Bulk Product 5b547138 | Clothing | $590.77 | 310 | ★ 2.8 | 0 | BULK-83d34836 |
| 12767 | Bulk Product 5bd1b2e8 | Books | $142.86 | 167 | ★ 1.2 | 78 | BULK-bd61b478 |
| 12768 | Bulk Product 560685c5 | Toys & Games | $329.31 | 478 | ★ 0.7 | 98 | BULK-a4ca1834 |
| 12769 | Bulk Product 71f43ebd | Toys & Games | $210.75 | 489 | ★ 3.7 | 16 | BULK-76819326 |
| 12770 | Bulk Product 66a7d3c7 | Clothing | $497.07 | 214 | ★ 3.4 | 2 | BULK-d90840ab |
| 12771 | Bulk Product b155f206 | Clothing | $342.52 | 214 | ★ 1.1 | 57 | BULK-59ae97e4 |
| 12772 | Bulk Product e9fc3a2a | Toys & Games | $468.47 | 74 | ★ 2.4 | 56 | BULK-9285e52a |
| 12773 | Bulk Product 457ca25c | Clothing | $332.80 | 370 | ★ 0.3 | 38 | BULK-6ae1d323 |
| 12774 | Bulk Product c63767c1 | Home & Garden | $224.39 | 395 | ★ 4.0 | 74 | BULK-c0a1c2f6 |
| 12775 | Bulk Product 6571aba7 | Electronics | $155.89 | 418 | ★ 4.9 | 19 | BULK-4bf00e3a |
| 12776 | Bulk Product 9f5ff354 | Toys & Games | $107.70 | 449 | ★ 3.5 | 87 | BULK-2f0a79b6 |
| 12777 | Bulk Product 04021911 | Clothing | $748.06 | 120 | ★ 2.7 | 62 | BULK-c5b276bd |
| 12778 | Bulk Product f773c3e0 | Electronics | $778.51 | 98 | ★ 1.1 | 2 | BULK-c8a85ea3 |
| 12779 | Bulk Product e5326822 | Sports & Outdoors | $985.68 | 242 | ★ 4.9 | 54 | BULK-cb78cf25 |
| 12780 | Bulk Product a0dfff55 | Clothing | $443.69 | 75 | ★ 2.0 | 88 | BULK-9990a6d6 |
| 12781 | Bulk Product 2642de3d | Sports & Outdoors | $916.42 | 275 | ★ 1.2 | 79 | BULK-36a742a2 |
| 12782 | Bulk Product 4f374b4e | Home & Garden | $25.99 | 390 | ★ 1.1 | 50 | BULK-82962048 |
| 12783 | Bulk Product 030689c8 | Home & Garden | $445.59 | 277 | ★ 2.2 | 21 | BULK-38e28c11 |
| 12784 | Bulk Product 2a03567f | Clothing | $56.42 | 144 | ★ 1.8 | 69 | BULK-16a5abbb |
// 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
};
}