Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4273 | Mega Home & Garden Product Special Edition | Home & Garden | $759.64 | 201 | ★ 2.9 | 802 | SKU-004273 |
| 4274 | Professional Toys & Games Product Lite | Toys & Games | $307.74 | 214 | ★ 3.7 | 531 | SKU-004274 |
| 4275 | Premium Health & Beauty Product Special Edition | Health & Beauty | $15.98 | 243 | ★ 2.7 | 620 | SKU-004275 |
| 4276 | Standard Books Product 2024 | Books | $828.42 | 193 | ★ 2.8 | 33 | SKU-004276 |
| 4277 | Super Clothing Product Special Edition | Clothing | $530.14 | 474 | ★ 3.9 | 184 | SKU-004277 |
| 4278 | Economy Books Product Advanced | Books | $902.42 | 54 | ★ 2.3 | 143 | SKU-004278 |
| 4279 | Standard Books Product Classic | Books | $774.44 | 369 | ★ 3.7 | 794 | SKU-004279 |
| 4280 | Ultra Home & Garden Product Plus | Home & Garden | $46.65 | 136 | ★ 2.4 | 831 | SKU-004280 |
| 4281 | Standard Toys & Games Product 2024 | Toys & Games | $242.81 | 100 | ★ 3.5 | 161 | SKU-004281 |
| 4282 | Standard Toys & Games Product 2024 | Toys & Games | $871.87 | 361 | ★ 3.7 | 69 | SKU-004282 |
| 4283 | Mega Sports & Outdoors Product XL | Sports & Outdoors | $693.57 | 65 | ★ 3.4 | 264 | SKU-004283 |
| 4284 | Super Home & Garden Product Max | Home & Garden | $551.84 | 46 | ★ 2.4 | 426 | SKU-004284 |
| 4285 | Standard Home & Garden Product Plus | Home & Garden | $726.21 | 12 | ★ 5.0 | 940 | SKU-004285 |
| 4287 | Standard Sports & Outdoors Product Special Edition | Sports & Outdoors | $659.95 | 257 | ★ 2.7 | 955 | SKU-004287 |
| 4290 | Super Clothing Product Pro | Clothing | $686.49 | 285 | ★ 2.6 | 700 | SKU-004290 |
| 4291 | Deluxe Books Product Advanced | Books | $211.09 | 286 | ★ 4.5 | 864 | SKU-004291 |
| 4292 | Pro Automotive Product Mini | Automotive | $150.44 | 356 | ★ 1.7 | 577 | SKU-004292 |
| 4293 | Economy Sports & Outdoors Product Mini | Sports & Outdoors | $985.82 | 436 | ★ 2.4 | 374 | SKU-004293 |
| 4294 | Professional Home & Garden Product Pro | Home & Garden | $153.89 | 140 | ★ 4.2 | 792 | SKU-004294 |
| 4295 | Ultra Home & Garden Product XL | Home & Garden | $811.40 | 103 | ★ 1.1 | 103 | SKU-004295 |
| 4297 | Professional Books Product Max | Books | $367.27 | 91 | ★ 1.3 | 786 | SKU-004297 |
| 4298 | Economy Food & Grocery Product Max | Food & Grocery | $941.06 | 284 | ★ 3.4 | 555 | SKU-004298 |
| 4301 | Deluxe Food & Grocery Product Plus | Food & Grocery | $423.72 | 288 | ★ 1.0 | 556 | SKU-004301 |
| 4302 | Professional Books Product Max | Books | $473.20 | 30 | ★ 3.3 | 913 | SKU-004302 |
| 4304 | Super Office Supplies Product 2024 | Office Supplies | $21.44 | 9 | ★ 3.5 | 278 | SKU-004304 |
// 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
};
}