Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 114 | Pro Office Supplies Product Special Edition | Office Supplies | $23.00 | 368 | ★ 4.7 | 506 | SKU-000114 |
| 116 | Elite Sports & Outdoors Product Classic | Sports & Outdoors | $227.59 | 419 | ★ 1.8 | 205 | SKU-000116 |
| 117 | Mega Electronics Product Special Edition | Electronics | $511.59 | 169 | ★ 5.0 | 653 | SKU-000117 |
| 118 | Deluxe Sports & Outdoors Product Special Edition | Sports & Outdoors | $339.35 | 398 | ★ 1.3 | 65 | SKU-000118 |
| 120 | Ultra Sports & Outdoors Product Special Edition | Sports & Outdoors | $78.73 | 212 | ★ 2.6 | 79 | SKU-000120 |
| 121 | Pro Toys & Games Product Special Edition | Toys & Games | $710.60 | 140 | ★ 1.5 | 746 | SKU-000121 |
| 123 | Pro Office Supplies Product Plus | Office Supplies | $531.52 | 184 | ★ 2.5 | 442 | SKU-000123 |
| 124 | Elite Home & Garden Product Classic | Home & Garden | $199.04 | 143 | ★ 2.8 | 339 | SKU-000124 |
| 125 | Elite Food & Grocery Product Advanced | Food & Grocery | $614.38 | 19 | ★ 1.0 | 51 | SKU-000125 |
| 126 | Mega Toys & Games Product Advanced | Toys & Games | $631.43 | 224 | ★ 1.3 | 677 | SKU-000126 |
| 127 | Super Toys & Games Product Advanced | Toys & Games | $220.16 | 268 | ★ 2.4 | 125 | SKU-000127 |
| 128 | Super Books Product 2024 | Books | $349.65 | 179 | ★ 2.0 | 148 | SKU-000128 |
| 129 | Pro Home & Garden Product Classic | Home & Garden | $313.20 | 31 | ★ 2.2 | 498 | SKU-000129 |
| 130 | Professional Automotive Product Lite | Automotive | $140.82 | 465 | ★ 1.3 | 379 | SKU-000130 |
| 131 | Pro Health & Beauty Product Classic | Health & Beauty | $465.54 | 71 | ★ 3.2 | 474 | SKU-000131 |
| 132 | Super Home & Garden Product XL | Home & Garden | $90.60 | 478 | ★ 1.1 | 137 | SKU-000132 |
| 133 | Deluxe Clothing Product Mini | Clothing | $174.34 | 32 | ★ 3.4 | 597 | SKU-000133 |
| 134 | Premium Sports & Outdoors Product Lite | Sports & Outdoors | $270.22 | 347 | ★ 3.5 | 540 | SKU-000134 |
| 135 | Premium Electronics Product Mini | Electronics | $728.45 | 254 | ★ 4.4 | 210 | SKU-000135 |
| 136 | Elite Sports & Outdoors Product Pro | Sports & Outdoors | $561.72 | 381 | ★ 3.2 | 728 | SKU-000136 |
| 137 | Economy Clothing Product Lite | Clothing | $599.35 | 134 | ★ 2.4 | 781 | SKU-000137 |
| 138 | Standard Books Product Pro | Books | $933.31 | 121 | ★ 4.8 | 964 | SKU-000138 |
| 139 | Professional Home & Garden Product Pro | Home & Garden | $756.02 | 255 | ★ 1.5 | 645 | SKU-000139 |
| 141 | Super Home & Garden Product Lite | Home & Garden | $171.89 | 219 | ★ 1.6 | 151 | SKU-000141 |
| 142 | Economy Health & Beauty Product Advanced | Health & Beauty | $95.15 | 399 | ★ 1.9 | 41 | SKU-000142 |
| 143 | Pro Office Supplies Product Plus | Office Supplies | $144.88 | 28 | ★ 1.6 | 346 | SKU-000143 |
| 144 | Ultra Toys & Games Product 2024 | Toys & Games | $489.32 | 222 | ★ 4.7 | 467 | SKU-000144 |
| 145 | Elite Clothing Product Mini | Clothing | $339.70 | 32 | ★ 2.2 | 111 | SKU-000145 |
| 146 | Economy Office Supplies Product Special Edition | Office Supplies | $937.15 | 117 | ★ 2.1 | 465 | SKU-000146 |
| 147 | Mega Electronics Product XL | Electronics | $409.99 | 189 | ★ 2.5 | 643 | SKU-000147 |
| 148 | Elite Toys & Games Product Special Edition | Toys & Games | $905.51 | 430 | ★ 4.2 | 675 | SKU-000148 |
| 149 | Economy Office Supplies Product Pro | Office Supplies | $211.18 | 226 | ★ 3.8 | 292 | SKU-000149 |
| 150 | Economy Health & Beauty Product 2024 | Health & Beauty | $937.12 | 282 | ★ 4.5 | 997 | SKU-000150 |
| 151 | Premium Electronics Product Lite | Electronics | $283.39 | 184 | ★ 3.3 | 935 | SKU-000151 |
| 152 | Ultra Electronics Product XL | Electronics | $673.87 | 394 | ★ 3.4 | 272 | SKU-000152 |
| 153 | Deluxe Sports & Outdoors Product XL | Sports & Outdoors | $842.02 | 149 | ★ 4.1 | 836 | SKU-000153 |
| 154 | Premium Clothing Product Lite | Clothing | $178.37 | 442 | ★ 4.9 | 884 | SKU-000154 |
| 155 | Super Health & Beauty Product Max | Health & Beauty | $241.56 | 437 | ★ 3.7 | 686 | SKU-000155 |
| 156 | Economy Home & Garden Product Mini | Home & Garden | $178.20 | 49 | ★ 3.9 | 387 | SKU-000156 |
| 157 | Standard Health & Beauty Product 2024 | Health & Beauty | $763.11 | 425 | ★ 4.5 | 961 | SKU-000157 |
| 158 | Economy Home & Garden Product Classic | Home & Garden | $476.52 | 384 | ★ 1.5 | 941 | SKU-000158 |
| 159 | Premium Office Supplies Product Plus | Office Supplies | $829.99 | 71 | ★ 2.8 | 339 | SKU-000159 |
| 160 | Elite Electronics Product Pro | Electronics | $177.06 | 254 | ★ 4.1 | 585 | SKU-000160 |
| 161 | Pro Office Supplies Product Lite | Office Supplies | $878.46 | 279 | ★ 4.4 | 780 | SKU-000161 |
| 162 | Deluxe Sports & Outdoors Product Classic | Sports & Outdoors | $976.17 | 41 | ★ 3.3 | 257 | SKU-000162 |
| 163 | Ultra Health & Beauty Product Advanced | Health & Beauty | $203.69 | 115 | ★ 3.9 | 921 | SKU-000163 |
| 164 | Professional Automotive Product Lite | Automotive | $676.90 | 55 | ★ 3.6 | 169 | SKU-000164 |
| 165 | Mega Electronics Product Advanced | Electronics | $225.52 | 382 | ★ 2.1 | 859 | SKU-000165 |
| 166 | Ultra Books Product Max | Books | $850.39 | 202 | ★ 2.8 | 3 | SKU-000166 |
| 167 | Professional Electronics Product Classic | Electronics | $190.98 | 216 | ★ 4.7 | 708 | SKU-000167 |
// 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
};
}