Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5610 | Bulk Product a63a66b7 | Clothing | $129.92 | 483 | ★ 3.9 | 92 | BULK-d5600f97 |
| 5611 | Bulk Product c80ac659 | Home & Garden | $40.67 | 140 | ★ 3.3 | 35 | BULK-61bb3956 |
| 5612 | Bulk Product 79040881 | Sports & Outdoors | $565.49 | 169 | ★ 0.5 | 48 | BULK-23133efe |
| 5613 | Bulk Product 20a210bd | Books | $225.85 | 288 | ★ 4.5 | 94 | BULK-b9d468f9 |
| 5614 | Bulk Product fdd17b66 | Toys & Games | $697.26 | 16 | ★ 1.7 | 50 | BULK-d687dee7 |
| 5615 | Bulk Product 06baeb28 | Toys & Games | $847.07 | 328 | ★ 2.2 | 38 | BULK-a0b3c049 |
| 5616 | Bulk Product d5d02161 | Toys & Games | $465.62 | 465 | ★ 3.4 | 10 | BULK-f71d69c3 |
| 5617 | Bulk Product c5724602 | Books | $817.08 | 235 | ★ 1.0 | 89 | BULK-a5cb81c7 |
| 5618 | Bulk Product 37144bc2 | Sports & Outdoors | $539.41 | 117 | ★ 4.6 | 1 | BULK-a3c70496 |
| 5619 | Bulk Product a335c2d2 | Clothing | $365.50 | 187 | ★ 1.7 | 54 | BULK-158fca20 |
| 5620 | Bulk Product 01be3198 | Sports & Outdoors | $893.15 | 152 | ★ 2.8 | 18 | BULK-3cb92784 |
| 5621 | Bulk Product 92969364 | Books | $805.72 | 118 | ★ 3.8 | 15 | BULK-e3a58112 |
| 5622 | Bulk Product b4e29c41 | Clothing | $477.60 | 349 | ★ 1.5 | 2 | BULK-7fd14ea0 |
| 5623 | Bulk Product 9d5473a8 | Toys & Games | $353.05 | 242 | ★ 0.3 | 85 | BULK-d741a33d |
| 5624 | Bulk Product a8efdc30 | Home & Garden | $685.08 | 112 | ★ 1.3 | 65 | BULK-f9a1ebfb |
| 5625 | Bulk Product 3d53b04e | Electronics | $808.95 | 48 | ★ 0.3 | 42 | BULK-73b41957 |
| 5626 | Bulk Product f105b8eb | Electronics | $46.02 | 422 | ★ 1.7 | 81 | BULK-c70dcf83 |
| 5627 | Bulk Product 8508c6fe | Electronics | $348.52 | 128 | ★ 1.8 | 86 | BULK-a4d0e45d |
| 5628 | Bulk Product bd1bba4b | Toys & Games | $998.10 | 470 | ★ 4.6 | 5 | BULK-2e550bbf |
| 5629 | Bulk Product 92ae6ca1 | Home & Garden | $195.54 | 73 | ★ 0.8 | 90 | BULK-1801317f |
| 5630 | Bulk Product 1a6e8260 | Clothing | $777.09 | 93 | ★ 2.0 | 45 | BULK-ceb2c4dd |
| 5631 | Bulk Product 651e293f | Toys & Games | $673.52 | 483 | ★ 1.3 | 45 | BULK-1db1c0cd |
| 5632 | Bulk Product ef6915ba | Electronics | $815.56 | 418 | ★ 2.6 | 15 | BULK-6bf3d246 |
| 5633 | Bulk Product 5b77b6f4 | Toys & Games | $372.71 | 37 | ★ 1.0 | 57 | BULK-58dd921f |
| 5634 | Bulk Product b66de828 | Toys & Games | $976.34 | 141 | ★ 3.9 | 53 | BULK-555ac4b9 |
// 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
};
}