Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4792 | Deluxe Health & Beauty Product Max | Health & Beauty | $689.73 | 155 | ★ 2.5 | 389 | SKU-004792 |
| 4793 | Elite Clothing Product Lite | Clothing | $961.69 | 247 | ★ 2.6 | 824 | SKU-004793 |
| 4794 | Standard Sports & Outdoors Product Max | Sports & Outdoors | $314.05 | 259 | ★ 4.4 | 94 | SKU-004794 |
| 4795 | Standard Toys & Games Product Max | Toys & Games | $316.71 | 206 | ★ 2.5 | 891 | SKU-004795 |
| 4796 | Mega Sports & Outdoors Product Plus | Sports & Outdoors | $680.45 | 64 | ★ 2.2 | 352 | SKU-004796 |
| 4797 | Economy Home & Garden Product Classic | Home & Garden | $304.05 | 461 | ★ 2.2 | 985 | SKU-004797 |
| 4798 | Pro Clothing Product Lite | Clothing | $39.07 | 291 | ★ 1.2 | 901 | SKU-004798 |
| 4799 | Economy Health & Beauty Product Classic | Health & Beauty | $102.30 | 19 | ★ 4.5 | 40 | SKU-004799 |
| 4800 | Mega Food & Grocery Product Mini | Food & Grocery | $107.78 | 145 | ★ 2.8 | 707 | SKU-004800 |
| 4801 | Economy Home & Garden Product Pro | Home & Garden | $514.33 | 453 | ★ 3.8 | 609 | SKU-004801 |
| 4802 | Deluxe Toys & Games Product Plus | Toys & Games | $970.02 | 348 | ★ 3.7 | 420 | SKU-004802 |
| 4804 | Professional Books Product Advanced | Books | $958.45 | 183 | ★ 2.3 | 15 | SKU-004804 |
| 4805 | Professional Toys & Games Product Special Edition | Toys & Games | $607.08 | 160 | ★ 2.2 | 581 | SKU-004805 |
| 4806 | Pro Home & Garden Product Mini | Home & Garden | $817.74 | 193 | ★ 1.5 | 995 | SKU-004806 |
| 4807 | Super Health & Beauty Product Classic | Health & Beauty | $826.40 | 393 | ★ 2.8 | 590 | SKU-004807 |
| 4809 | Standard Clothing Product XL | Clothing | $374.80 | 171 | ★ 2.2 | 568 | SKU-004809 |
| 4810 | Pro Electronics Product Pro | Electronics | $553.56 | 114 | ★ 2.8 | 274 | SKU-004810 |
| 4811 | Mega Sports & Outdoors Product 2024 | Sports & Outdoors | $373.60 | 163 | ★ 1.9 | 60 | SKU-004811 |
| 4812 | Professional Clothing Product Lite | Clothing | $226.84 | 119 | ★ 2.4 | 851 | SKU-004812 |
| 4814 | Deluxe Electronics Product Lite | Electronics | $923.36 | 347 | ★ 2.8 | 778 | SKU-004814 |
| 4815 | Elite Books Product Lite | Books | $393.86 | 127 | ★ 1.4 | 926 | SKU-004815 |
| 4816 | Professional Toys & Games Product Pro | Toys & Games | $95.62 | 75 | ★ 1.2 | 900 | SKU-004816 |
| 4817 | Professional Toys & Games Product Mini | Toys & Games | $562.79 | 262 | ★ 3.4 | 512 | SKU-004817 |
| 4818 | Mega Electronics Product 2024 | Electronics | $265.15 | 219 | ★ 4.6 | 234 | SKU-004818 |
| 4819 | Deluxe Food & Grocery Product Mini | Food & Grocery | $452.01 | 99 | ★ 4.7 | 722 | SKU-004819 |
// 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
};
}