Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15110 | Bulk Product f0f6e80f | Clothing | $70.23 | 234 | ★ 2.4 | 95 | BULK-ea202861 |
| 15111 | Bulk Product c764db4a | Home & Garden | $11.05 | 345 | ★ 1.4 | 8 | BULK-2acefeeb |
| 15112 | Bulk Product b1385555 | Home & Garden | $661.72 | 214 | ★ 1.1 | 55 | BULK-322963a8 |
| 15113 | Bulk Product 927af288 | Electronics | $649.44 | 11 | ★ 3.7 | 58 | BULK-4dec50ba |
| 15114 | Bulk Product cff88055 | Clothing | $28.95 | 400 | ★ 1.3 | 0 | BULK-7b8f5848 |
| 15115 | Bulk Product c8cd97b7 | Toys & Games | $343.47 | 325 | ★ 3.0 | 28 | BULK-aa223a94 |
| 15116 | Bulk Product 14851b51 | Sports & Outdoors | $703.58 | 378 | ★ 3.8 | 83 | BULK-bfeb6884 |
| 15117 | Bulk Product 36d2548d | Home & Garden | $173.81 | 50 | ★ 2.4 | 18 | BULK-bb605b33 |
| 15118 | Bulk Product e83f1b48 | Books | $613.03 | 66 | ★ 1.0 | 80 | BULK-c5b6e054 |
| 15119 | Bulk Product 5b5c6dcb | Electronics | $220.81 | 43 | ★ 2.4 | 65 | BULK-c648d414 |
| 15120 | Bulk Product b2a6cabb | Toys & Games | $121.93 | 202 | ★ 2.8 | 15 | BULK-df4f2594 |
| 15121 | Bulk Product 54577a75 | Toys & Games | $855.51 | 383 | ★ 0.3 | 12 | BULK-58c182dc |
| 15122 | Bulk Product 7144f961 | Books | $703.18 | 174 | ★ 4.4 | 51 | BULK-560fa3ac |
| 15123 | Bulk Product 2e740f5f | Home & Garden | $850.63 | 121 | ★ 1.0 | 53 | BULK-b587d9eb |
| 15124 | Bulk Product fa51f3d0 | Home & Garden | $554.00 | 384 | ★ 4.9 | 2 | BULK-c4fbcec8 |
| 15125 | Bulk Product 4f019c93 | Toys & Games | $118.91 | 41 | ★ 1.9 | 98 | BULK-16f82c58 |
| 15126 | Bulk Product fd2c0f96 | Clothing | $737.30 | 199 | ★ 3.3 | 85 | BULK-95d57c57 |
| 15127 | Bulk Product ed92a138 | Electronics | $985.79 | 94 | ★ 2.7 | 44 | BULK-38e27fa0 |
| 15128 | Bulk Product 00518a7a | Electronics | $669.44 | 58 | ★ 0.8 | 11 | BULK-dca9c6f1 |
| 15129 | Bulk Product ad915e65 | Sports & Outdoors | $698.98 | 255 | ★ 3.4 | 88 | BULK-4f2bde0f |
| 15130 | Bulk Product e89e54cc | Sports & Outdoors | $410.90 | 340 | ★ 0.2 | 57 | BULK-1390b9a2 |
| 15131 | Bulk Product f90eeed1 | Electronics | $962.86 | 91 | ★ 0.9 | 57 | BULK-2f850664 |
| 15132 | Bulk Product 8df7a216 | Home & Garden | $454.44 | 120 | ★ 0.8 | 35 | BULK-7eadee40 |
| 15133 | Bulk Product ee185df8 | Sports & Outdoors | $648.72 | 141 | ★ 0.7 | 18 | BULK-5e1e9f16 |
| 15134 | Bulk Product 71b40862 | Books | $956.18 | 205 | ★ 0.0 | 33 | BULK-04d428ea |
// 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
};
}