Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 13660 | Bulk Product 411799b9 | Clothing | $554.17 | 433 | ★ 4.6 | 60 | BULK-4992f4a6 |
| 13661 | Bulk Product 31c8e4cd | Sports & Outdoors | $178.25 | 355 | ★ 1.7 | 40 | BULK-9f910804 |
| 13662 | Bulk Product e5e76686 | Books | $532.40 | 212 | ★ 3.5 | 54 | BULK-e0e75412 |
| 13663 | Bulk Product 368154d5 | Home & Garden | $384.10 | 76 | ★ 3.8 | 99 | BULK-a6d36c7b |
| 13664 | Bulk Product 2a9a0d25 | Electronics | $324.99 | 422 | ★ 2.1 | 72 | BULK-3f71304c |
| 13665 | Bulk Product 921788a8 | Books | $862.82 | 140 | ★ 3.6 | 33 | BULK-40de3ecb |
| 13666 | Bulk Product 3d666bdd | Sports & Outdoors | $258.82 | 300 | ★ 5.0 | 64 | BULK-3ae8cbef |
| 13667 | Bulk Product 5d24d2fe | Books | $896.41 | 240 | ★ 4.5 | 3 | BULK-c7ea0cdb |
| 13668 | Bulk Product caa21d69 | Books | $341.99 | 398 | ★ 0.9 | 70 | BULK-4dd7d29a |
| 13669 | Bulk Product 22439ef5 | Books | $152.20 | 156 | ★ 3.1 | 89 | BULK-d55b6ea8 |
| 13670 | Bulk Product c98cc5dc | Sports & Outdoors | $92.36 | 280 | ★ 1.0 | 55 | BULK-4f9ccd8c |
| 13671 | Bulk Product 65e79418 | Toys & Games | $175.34 | 291 | ★ 4.5 | 47 | BULK-920dbbec |
| 13672 | Bulk Product 2f7a2e3d | Clothing | $514.43 | 113 | ★ 2.6 | 16 | BULK-44206da4 |
| 13673 | Bulk Product 71561678 | Books | $827.66 | 268 | ★ 2.9 | 14 | BULK-546479e2 |
| 13674 | Bulk Product 7edc3ff9 | Books | $982.98 | 227 | ★ 0.5 | 79 | BULK-b4da5e11 |
| 13675 | Bulk Product 598ebf15 | Books | $303.68 | 387 | ★ 4.5 | 20 | BULK-bb693eff |
| 13676 | Bulk Product 85dc37b3 | Home & Garden | $622.77 | 208 | ★ 0.5 | 75 | BULK-c5c5c31b |
| 13677 | Bulk Product 7773c104 | Home & Garden | $36.04 | 298 | ★ 3.2 | 14 | BULK-6c0ef46a |
| 13678 | Bulk Product 662495a6 | Toys & Games | $213.50 | 191 | ★ 3.3 | 5 | BULK-b816ddb9 |
| 13679 | Bulk Product b9c44632 | Electronics | $388.90 | 182 | ★ 1.6 | 87 | BULK-4e6f8547 |
| 13680 | Bulk Product e21a64a9 | Clothing | $893.83 | 102 | ★ 1.8 | 37 | BULK-706dcbe4 |
| 13681 | Bulk Product 064611ad | Electronics | $572.80 | 99 | ★ 1.4 | 16 | BULK-783c3c27 |
| 13682 | Bulk Product e5923c3b | Clothing | $796.74 | 249 | ★ 2.7 | 74 | BULK-9e11a4dd |
| 13683 | Bulk Product 179a2168 | Home & Garden | $959.81 | 371 | ★ 1.6 | 99 | BULK-6d454914 |
| 13684 | Bulk Product 3e4f87cd | Clothing | $549.10 | 69 | ★ 3.9 | 53 | BULK-a4bbb9d5 |
// 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
};
}