Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4220 | Mega Sports & Outdoors Product Max | Sports & Outdoors | $198.09 | 465 | ★ 3.4 | 245 | SKU-004220 |
| 4221 | Elite Home & Garden Product 2024 | Home & Garden | $587.33 | 313 | ★ 3.0 | 680 | SKU-004221 |
| 4222 | Super Office Supplies Product Lite | Office Supplies | $150.53 | 195 | ★ 1.3 | 848 | SKU-004222 |
| 4223 | Professional Toys & Games Product Lite | Toys & Games | $797.00 | 318 | ★ 4.4 | 571 | SKU-004223 |
| 4224 | Pro Clothing Product Advanced | Clothing | $223.50 | 497 | ★ 4.6 | 414 | SKU-004224 |
| 4225 | Economy Food & Grocery Product Max | Food & Grocery | $697.29 | 393 | ★ 2.4 | 454 | SKU-004225 |
| 4226 | Professional Sports & Outdoors Product Advanced | Sports & Outdoors | $398.68 | 494 | ★ 1.9 | 651 | SKU-004226 |
| 4227 | Ultra Automotive Product 2024 | Automotive | $282.98 | 343 | ★ 4.2 | 590 | SKU-004227 |
| 4228 | Deluxe Food & Grocery Product Advanced | Food & Grocery | $42.31 | 335 | ★ 3.1 | 430 | SKU-004228 |
| 4229 | Economy Home & Garden Product 2024 | Home & Garden | $863.10 | 492 | ★ 1.7 | 170 | SKU-004229 |
| 4231 | Standard Automotive Product Pro | Automotive | $62.44 | 42 | ★ 5.0 | 365 | SKU-004231 |
| 4232 | Deluxe Electronics Product Lite | Electronics | $201.06 | 470 | ★ 1.4 | 597 | SKU-004232 |
| 4233 | Deluxe Food & Grocery Product Max | Food & Grocery | $483.17 | 127 | ★ 4.7 | 263 | SKU-004233 |
| 4234 | Premium Clothing Product Mini | Clothing | $370.11 | 130 | ★ 2.7 | 725 | SKU-004234 |
| 4235 | Pro Toys & Games Product Special Edition | Toys & Games | $898.49 | 181 | ★ 4.3 | 282 | SKU-004235 |
| 4237 | Economy Home & Garden Product Mini | Home & Garden | $558.05 | 349 | ★ 1.0 | 902 | SKU-004237 |
| 4238 | Pro Home & Garden Product Lite | Home & Garden | $183.12 | 335 | ★ 1.0 | 493 | SKU-004238 |
| 4239 | Mega Office Supplies Product Advanced | Office Supplies | $342.15 | 68 | ★ 4.3 | 571 | SKU-004239 |
| 4240 | Ultra Automotive Product Plus | Automotive | $962.98 | 359 | ★ 4.2 | 438 | SKU-004240 |
| 4241 | Mega Automotive Product Mini | Automotive | $919.39 | 396 | ★ 3.7 | 457 | SKU-004241 |
| 4242 | Elite Office Supplies Product 2024 | Office Supplies | $83.86 | 68 | ★ 4.4 | 529 | SKU-004242 |
| 4243 | Elite Books Product XL | Books | $303.44 | 327 | ★ 2.8 | 473 | SKU-004243 |
| 4244 | Pro Automotive Product Special Edition | Automotive | $727.81 | 122 | ★ 2.6 | 916 | SKU-004244 |
| 4245 | Premium Toys & Games Product Max | Toys & Games | $44.76 | 161 | ★ 1.5 | 216 | SKU-004245 |
| 4246 | Premium Health & Beauty Product Pro | Health & Beauty | $190.79 | 482 | ★ 4.4 | 542 | SKU-004246 |
// 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
};
}