Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9260 | Bulk Product eff6663a | Home & Garden | $179.55 | 265 | ★ 0.4 | 3 | BULK-1bfa36b5 |
| 9261 | Bulk Product 5f0fd613 | Home & Garden | $78.00 | 481 | ★ 0.1 | 97 | BULK-0a7eb26c |
| 9262 | Bulk Product a3222762 | Toys & Games | $811.55 | 327 | ★ 3.0 | 35 | BULK-4ff58d84 |
| 9263 | Bulk Product f3db265a | Books | $856.91 | 275 | ★ 0.2 | 34 | BULK-d0b4627c |
| 9264 | Bulk Product 2a39c5c9 | Clothing | $61.75 | 449 | ★ 4.0 | 30 | BULK-c4fcb92b |
| 9265 | Bulk Product 927ebc59 | Electronics | $457.79 | 422 | ★ 3.4 | 49 | BULK-feffd582 |
| 9266 | Bulk Product 73f99c9f | Clothing | $477.24 | 407 | ★ 2.6 | 47 | BULK-ddb3d67e |
| 9267 | Bulk Product 8305ec30 | Books | $192.55 | 172 | ★ 2.4 | 28 | BULK-ac24f1a9 |
| 9268 | Bulk Product 067cff6c | Toys & Games | $357.42 | 382 | ★ 2.0 | 14 | BULK-149dd806 |
| 9269 | Bulk Product b9eb9376 | Clothing | $111.09 | 173 | ★ 0.5 | 34 | BULK-76d53006 |
| 9270 | Bulk Product ec1cdbab | Clothing | $43.34 | 94 | ★ 4.2 | 18 | BULK-4c3a77db |
| 9271 | Bulk Product fdf933d8 | Books | $761.01 | 153 | ★ 4.1 | 48 | BULK-b5955457 |
| 9272 | Bulk Product a32fbcf0 | Books | $73.17 | 428 | ★ 2.8 | 73 | BULK-2af22fce |
| 9273 | Bulk Product b9704f60 | Clothing | $948.53 | 16 | ★ 1.4 | 46 | BULK-02ed7198 |
| 9274 | Bulk Product 03f6e52b | Home & Garden | $1,008.74 | 494 | ★ 0.4 | 79 | BULK-6f575d0f |
| 9275 | Bulk Product 95d07246 | Electronics | $584.79 | 12 | ★ 1.8 | 12 | BULK-e7dbfd6c |
| 9276 | Bulk Product a7e059d0 | Sports & Outdoors | $780.54 | 182 | ★ 3.2 | 86 | BULK-3e63a97e |
| 9277 | Bulk Product 787846b1 | Electronics | $509.02 | 415 | ★ 3.1 | 31 | BULK-de0d7270 |
| 9278 | Bulk Product 206fbc33 | Home & Garden | $124.04 | 485 | ★ 1.5 | 19 | BULK-1c415711 |
| 9279 | Bulk Product f706eb3b | Toys & Games | $669.15 | 95 | ★ 2.6 | 92 | BULK-ce4708c4 |
| 9280 | Bulk Product 16e5b225 | Books | $246.51 | 213 | ★ 1.3 | 91 | BULK-1ef43021 |
| 9281 | Bulk Product 5a8dd13a | Toys & Games | $37.93 | 295 | ★ 1.5 | 82 | BULK-97cca4d8 |
| 9282 | Bulk Product afb0d22d | Electronics | $450.28 | 104 | ★ 1.9 | 39 | BULK-55cf87ca |
| 9283 | Bulk Product b0cc11df | Sports & Outdoors | $395.01 | 377 | ★ 2.7 | 23 | BULK-3b021c67 |
| 9284 | Bulk Product 8c4940a6 | Books | $826.80 | 161 | ★ 1.6 | 33 | BULK-3232f1ef |
// 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
};
}