Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3791 | Ultra Office Supplies Product Advanced | Office Supplies | $285.07 | 405 | ★ 1.7 | 894 | SKU-003791 |
| 3792 | Ultra Toys & Games Product 2024 | Toys & Games | $391.34 | 457 | ★ 2.2 | 343 | SKU-003792 |
| 3793 | Professional Toys & Games Product Pro | Toys & Games | $188.86 | 399 | ★ 4.8 | 344 | SKU-003793 |
| 3794 | Premium Toys & Games Product Special Edition | Toys & Games | $948.36 | 328 | ★ 3.8 | 789 | SKU-003794 |
| 3795 | Deluxe Clothing Product XL | Clothing | $127.50 | 474 | ★ 1.9 | 982 | SKU-003795 |
| 3796 | Mega Books Product Special Edition | Books | $568.16 | 294 | ★ 2.8 | 605 | SKU-003796 |
| 3797 | Ultra Home & Garden Product Advanced | Home & Garden | $173.09 | 354 | ★ 5.0 | 633 | SKU-003797 |
| 3798 | Deluxe Office Supplies Product Advanced | Office Supplies | $270.02 | 303 | ★ 1.9 | 159 | SKU-003798 |
| 3799 | Premium Automotive Product Pro | Automotive | $412.88 | 246 | ★ 1.0 | 464 | SKU-003799 |
| 3800 | Professional Books Product 2024 | Books | $253.84 | 444 | ★ 2.5 | 290 | SKU-003800 |
| 3801 | Standard Automotive Product Special Edition | Automotive | $271.97 | 264 | ★ 2.2 | 978 | SKU-003801 |
| 3802 | Standard Office Supplies Product Pro | Office Supplies | $319.29 | 92 | ★ 1.8 | 184 | SKU-003802 |
| 3803 | Standard Food & Grocery Product XL | Food & Grocery | $18.73 | 414 | ★ 4.5 | 563 | SKU-003803 |
| 3804 | Standard Sports & Outdoors Product Classic | Sports & Outdoors | $477.55 | 199 | ★ 3.8 | 351 | SKU-003804 |
| 3805 | Professional Clothing Product Mini | Clothing | $992.70 | 266 | ★ 2.6 | 181 | SKU-003805 |
| 3806 | Ultra Clothing Product Max | Clothing | $809.90 | 71 | ★ 1.7 | 33 | SKU-003806 |
| 3807 | Super Books Product Mini | Books | $22.80 | 126 | ★ 2.1 | 558 | SKU-003807 |
| 3808 | Ultra Toys & Games Product Max | Toys & Games | $95.40 | 224 | ★ 3.9 | 771 | SKU-003808 |
| 3809 | Economy Food & Grocery Product Classic | Food & Grocery | $149.29 | 104 | ★ 3.2 | 895 | SKU-003809 |
| 3810 | Economy Clothing Product Lite | Clothing | $637.25 | 316 | ★ 4.3 | 231 | SKU-003810 |
| 3811 | Premium Toys & Games Product XL | Toys & Games | $850.84 | 194 | ★ 3.4 | 254 | SKU-003811 |
| 3812 | Pro Health & Beauty Product Classic | Health & Beauty | $378.03 | 223 | ★ 3.6 | 237 | SKU-003812 |
| 3813 | Pro Toys & Games Product Plus | Toys & Games | $736.45 | 154 | ★ 4.5 | 918 | SKU-003813 |
| 3814 | Standard Clothing Product Pro | Clothing | $197.02 | 368 | ★ 2.0 | 449 | SKU-003814 |
| 3815 | Standard Health & Beauty Product Classic | Health & Beauty | $742.74 | 384 | ★ 4.1 | 11 | SKU-003815 |
// 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
};
}