Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 19510 | Bulk Product 5ce3818f | Books | $396.52 | 283 | ★ 2.9 | 15 | BULK-bf99a26f |
| 19511 | Bulk Product cdb54bb0 | Electronics | $53.54 | 20 | ★ 0.9 | 33 | BULK-039e9a79 |
| 19512 | Bulk Product ba7723cb | Electronics | $287.73 | 140 | ★ 1.8 | 5 | BULK-2e80ab4f |
| 19513 | Bulk Product 1ac74d91 | Books | $18.32 | 95 | ★ 3.6 | 6 | BULK-378c97da |
| 19514 | Bulk Product 10116cb6 | Electronics | $951.07 | 409 | ★ 1.0 | 24 | BULK-c144dbca |
| 19515 | Bulk Product a03f3cab | Electronics | $729.18 | 24 | ★ 4.3 | 18 | BULK-67626a36 |
| 19516 | Bulk Product f6f7b3b0 | Electronics | $916.06 | 321 | ★ 0.1 | 58 | BULK-4f3295fd |
| 19517 | Bulk Product 28b19720 | Electronics | $904.44 | 136 | ★ 4.0 | 5 | BULK-2c803487 |
| 19518 | Bulk Product c62c842e | Sports & Outdoors | $758.13 | 451 | ★ 3.5 | 6 | BULK-b79f229f |
| 19519 | Bulk Product 44f9f112 | Sports & Outdoors | $10.23 | 133 | ★ 4.8 | 46 | BULK-2e0e7cdc |
| 19520 | Bulk Product c36162ce | Sports & Outdoors | $479.06 | 291 | ★ 4.5 | 56 | BULK-b27e33b3 |
| 19521 | Bulk Product 1597381f | Electronics | $375.52 | 250 | ★ 1.4 | 94 | BULK-c4e4c4a8 |
| 19522 | Bulk Product a13cdbfe | Clothing | $217.13 | 426 | ★ 4.3 | 97 | BULK-a9addd9a |
| 19523 | Bulk Product 245de6eb | Home & Garden | $638.43 | 274 | ★ 2.8 | 74 | BULK-39258e8e |
| 19524 | Bulk Product 15a65ff4 | Electronics | $343.69 | 470 | ★ 3.2 | 90 | BULK-8d7b7233 |
| 19525 | Bulk Product c30b13fa | Electronics | $239.69 | 0 | ★ 4.0 | 91 | BULK-d961c25d |
| 19526 | Bulk Product 6e7a061a | Electronics | $958.41 | 392 | ★ 4.5 | 54 | BULK-7438d918 |
| 19527 | Bulk Product f999f3a8 | Sports & Outdoors | $315.31 | 263 | ★ 2.8 | 27 | BULK-fa01e936 |
| 19528 | Bulk Product f8d049cf | Books | $210.21 | 362 | ★ 4.3 | 29 | BULK-abeb4ba2 |
| 19529 | Bulk Product e695ea42 | Home & Garden | $12.05 | 5 | ★ 1.7 | 91 | BULK-3b96ceb4 |
| 19530 | Bulk Product cd2a806e | Electronics | $589.40 | 216 | ★ 4.5 | 77 | BULK-33ee8170 |
| 19531 | Bulk Product 0f25e554 | Home & Garden | $87.45 | 351 | ★ 3.8 | 66 | BULK-c923cb37 |
| 19532 | Bulk Product a903727f | Clothing | $507.78 | 391 | ★ 1.1 | 33 | BULK-5d0adbad |
| 19533 | Bulk Product 79d24c44 | Sports & Outdoors | $545.25 | 203 | ★ 2.3 | 62 | BULK-f864bd79 |
| 19534 | Bulk Product a8907a2c | Toys & Games | $545.25 | 372 | ★ 1.9 | 66 | BULK-613544d1 |
// 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
};
}