Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 12210 | Bulk Product 9153e499 | Clothing | $773.63 | 430 | ★ 4.8 | 30 | BULK-1de5c2f5 |
| 12211 | Bulk Product b7078533 | Toys & Games | $855.08 | 45 | ★ 2.4 | 16 | BULK-26d68af4 |
| 12212 | Bulk Product ec0f9d1a | Electronics | $782.44 | 379 | ★ 3.9 | 86 | BULK-fb39914e |
| 12213 | Bulk Product ca9739a3 | Clothing | $907.23 | 377 | ★ 0.7 | 21 | BULK-ab6384a3 |
| 12214 | Bulk Product 62b185e1 | Sports & Outdoors | $386.79 | 284 | ★ 0.6 | 67 | BULK-b5a7fab1 |
| 12215 | Bulk Product 9472cb99 | Books | $537.00 | 362 | ★ 2.4 | 1 | BULK-bf7fd2f6 |
| 12216 | Bulk Product a20ea724 | Electronics | $849.10 | 462 | ★ 0.3 | 23 | BULK-d9266431 |
| 12217 | Bulk Product 471b97c6 | Sports & Outdoors | $599.03 | 178 | ★ 3.8 | 55 | BULK-cbc8404d |
| 12218 | Bulk Product 8d51755d | Sports & Outdoors | $555.59 | 94 | ★ 4.9 | 25 | BULK-ab83a326 |
| 12219 | Bulk Product a4fb50fa | Sports & Outdoors | $393.83 | 57 | ★ 1.5 | 45 | BULK-1b1f9b35 |
| 12220 | Bulk Product 31e2f06b | Home & Garden | $728.10 | 347 | ★ 0.3 | 9 | BULK-5aadafee |
| 12221 | Bulk Product e9715f9f | Books | $448.81 | 493 | ★ 3.2 | 96 | BULK-eadac8cd |
| 12222 | Bulk Product 7d5f47b2 | Toys & Games | $101.51 | 322 | ★ 2.9 | 24 | BULK-34dda4b6 |
| 12223 | Bulk Product 2cf8c450 | Electronics | $873.79 | 494 | ★ 3.5 | 81 | BULK-1bb5a93d |
| 12224 | Bulk Product fd66c76a | Clothing | $817.16 | 155 | ★ 2.1 | 62 | BULK-35881a2e |
| 12225 | Bulk Product 49a3d791 | Home & Garden | $30.69 | 63 | ★ 0.1 | 59 | BULK-63dc786b |
| 12226 | Bulk Product dce4b1a3 | Books | $708.36 | 354 | ★ 0.8 | 21 | BULK-cb3fee66 |
| 12227 | Bulk Product d9016474 | Toys & Games | $469.97 | 67 | ★ 4.7 | 1 | BULK-d34f1701 |
| 12228 | Bulk Product ee4be162 | Toys & Games | $438.75 | 357 | ★ 4.2 | 85 | BULK-1cc1bba2 |
| 12229 | Bulk Product 7d099b50 | Sports & Outdoors | $972.92 | 412 | ★ 1.7 | 52 | BULK-8bf1b92b |
| 12230 | Bulk Product d054a199 | Electronics | $376.42 | 417 | ★ 2.5 | 10 | BULK-08a8a171 |
| 12231 | Bulk Product 041420ce | Sports & Outdoors | $302.04 | 446 | ★ 4.5 | 35 | BULK-ed4b949f |
| 12232 | Bulk Product ba122b95 | Home & Garden | $746.38 | 431 | ★ 3.1 | 68 | BULK-0e164f78 |
| 12233 | Bulk Product 8f10fbd4 | Toys & Games | $429.99 | 399 | ★ 3.4 | 59 | BULK-0659b3ee |
| 12234 | Bulk Product 9bdba883 | Electronics | $931.75 | 61 | ★ 1.3 | 14 | BULK-e922d5e2 |
// 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
};
}