Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3905 | Professional Sports & Outdoors Product XL | Sports & Outdoors | $155.46 | 238 | ★ 2.8 | 469 | SKU-003905 |
| 3906 | Pro Clothing Product Advanced | Clothing | $107.48 | 236 | ★ 1.8 | 31 | SKU-003906 |
| 3907 | Pro Health & Beauty Product Max | Health & Beauty | $524.06 | 309 | ★ 4.3 | 946 | SKU-003907 |
| 3908 | Economy Health & Beauty Product Pro | Health & Beauty | $787.63 | 250 | ★ 4.9 | 129 | SKU-003908 |
| 3909 | Premium Automotive Product Classic | Automotive | $846.84 | 452 | ★ 2.4 | 443 | SKU-003909 |
| 3910 | Super Automotive Product XL | Automotive | $26.29 | 360 | ★ 1.3 | 62 | SKU-003910 |
| 3911 | Super Office Supplies Product Max | Office Supplies | $258.12 | 187 | ★ 1.6 | 349 | SKU-003911 |
| 3912 | Professional Health & Beauty Product Classic | Health & Beauty | $572.63 | 449 | ★ 2.2 | 949 | SKU-003912 |
| 3914 | Premium Home & Garden Product Pro | Home & Garden | $213.58 | 416 | ★ 4.6 | 842 | SKU-003914 |
| 3915 | Economy Sports & Outdoors Product Special Edition | Sports & Outdoors | $335.38 | 110 | ★ 3.8 | 795 | SKU-003915 |
| 3916 | Ultra Health & Beauty Product Plus | Health & Beauty | $778.58 | 145 | ★ 2.0 | 971 | SKU-003916 |
| 3917 | Deluxe Home & Garden Product Plus | Home & Garden | $578.02 | 68 | ★ 3.8 | 383 | SKU-003917 |
| 3919 | Super Electronics Product Pro | Electronics | $25.62 | 406 | ★ 4.9 | 980 | SKU-003919 |
| 3920 | Elite Sports & Outdoors Product Plus | Sports & Outdoors | $881.99 | 168 | ★ 2.3 | 833 | SKU-003920 |
| 3921 | Ultra Office Supplies Product Advanced | Office Supplies | $762.86 | 462 | ★ 1.2 | 62 | SKU-003921 |
| 3922 | Ultra Clothing Product Lite | Clothing | $473.97 | 267 | ★ 3.8 | 9 | SKU-003922 |
| 3923 | Standard Electronics Product Max | Electronics | $891.02 | 168 | ★ 4.5 | 123 | SKU-003923 |
| 3924 | Mega Automotive Product Max | Automotive | $232.57 | 285 | ★ 4.3 | 156 | SKU-003924 |
| 3925 | Super Sports & Outdoors Product Special Edition | Sports & Outdoors | $479.89 | 67 | ★ 3.8 | 620 | SKU-003925 |
| 3926 | Mega Health & Beauty Product Pro | Health & Beauty | $872.61 | 124 | ★ 2.1 | 603 | SKU-003926 |
| 3927 | Standard Sports & Outdoors Product Mini | Sports & Outdoors | $219.85 | 319 | ★ 2.4 | 505 | SKU-003927 |
| 3928 | Pro Food & Grocery Product Special Edition | Food & Grocery | $130.39 | 243 | ★ 4.5 | 721 | SKU-003928 |
| 3929 | Super Sports & Outdoors Product Pro | Sports & Outdoors | $333.95 | 32 | ★ 3.7 | 26 | SKU-003929 |
| 3930 | Mega Automotive Product Advanced | Automotive | $894.54 | 296 | ★ 2.6 | 900 | SKU-003930 |
| 3931 | Professional Toys & Games Product Advanced | Toys & Games | $180.80 | 76 | ★ 4.4 | 717 | SKU-003931 |
// 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
};
}