Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4167 | Mega Sports & Outdoors Product Classic | Sports & Outdoors | $142.00 | 57 | ★ 1.8 | 753 | SKU-004167 |
| 4168 | Elite Books Product Lite | Books | $787.63 | 464 | ★ 1.2 | 702 | SKU-004168 |
| 4169 | Elite Office Supplies Product Pro | Office Supplies | $905.27 | 78 | ★ 2.5 | 458 | SKU-004169 |
| 4170 | Mega Clothing Product XL | Clothing | $14.01 | 100 | ★ 1.6 | 876 | SKU-004170 |
| 4171 | Ultra Office Supplies Product XL | Office Supplies | $123.54 | 199 | ★ 2.0 | 814 | SKU-004171 |
| 4172 | Pro Automotive Product Special Edition | Automotive | $212.85 | 292 | ★ 3.3 | 55 | SKU-004172 |
| 4173 | Economy Clothing Product Max | Clothing | $736.17 | 45 | ★ 3.5 | 695 | SKU-004173 |
| 4174 | Standard Home & Garden Product XL | Home & Garden | $190.65 | 126 | ★ 2.6 | 468 | SKU-004174 |
| 4175 | Mega Automotive Product Lite | Automotive | $781.91 | 226 | ★ 3.0 | 197 | SKU-004175 |
| 4176 | Pro Automotive Product Max | Automotive | $59.91 | 9 | ★ 3.1 | 583 | SKU-004176 |
| 4177 | Economy Electronics Product Plus | Electronics | $470.84 | 113 | ★ 3.5 | 561 | SKU-004177 |
| 4178 | Pro Toys & Games Product Plus | Toys & Games | $459.45 | 228 | ★ 4.4 | 320 | SKU-004178 |
| 4179 | Ultra Clothing Product Mini | Clothing | $506.70 | 215 | ★ 2.5 | 241 | SKU-004179 |
| 4180 | Economy Automotive Product Lite | Automotive | $256.10 | 294 | ★ 1.6 | 534 | SKU-004180 |
| 4181 | Professional Clothing Product Classic | Clothing | $894.04 | 142 | ★ 3.3 | 283 | SKU-004181 |
| 4182 | Elite Electronics Product Advanced | Electronics | $673.06 | 442 | ★ 4.7 | 348 | SKU-004182 |
| 4184 | Professional Clothing Product Mini | Clothing | $50.39 | 470 | ★ 2.7 | 295 | SKU-004184 |
| 4185 | Ultra Food & Grocery Product 2024 | Food & Grocery | $984.49 | 209 | ★ 4.5 | 908 | SKU-004185 |
| 4186 | Mega Books Product Classic | Books | $754.30 | 265 | ★ 3.3 | 966 | SKU-004186 |
| 4187 | Economy Food & Grocery Product Advanced | Food & Grocery | $448.35 | 475 | ★ 1.4 | 827 | SKU-004187 |
| 4188 | Deluxe Health & Beauty Product Lite | Health & Beauty | $194.85 | 353 | ★ 3.4 | 179 | SKU-004188 |
| 4189 | Super Home & Garden Product Pro | Home & Garden | $322.68 | 494 | ★ 2.7 | 293 | SKU-004189 |
| 4190 | Deluxe Health & Beauty Product Special Edition | Health & Beauty | $163.31 | 373 | ★ 4.1 | 858 | SKU-004190 |
| 4191 | Elite Clothing Product Classic | Clothing | $936.24 | 54 | ★ 4.8 | 798 | SKU-004191 |
| 4192 | Pro Food & Grocery Product 2024 | Food & Grocery | $780.86 | 132 | ★ 4.9 | 278 | SKU-004192 |
| 4193 | Economy Books Product Max | Books | $301.10 | 457 | ★ 3.2 | 524 | SKU-004193 |
| 4194 | Standard Books Product Mini | Books | $791.36 | 112 | ★ 1.1 | 101 | SKU-004194 |
| 4195 | Premium Toys & Games Product Special Edition | Toys & Games | $563.26 | 381 | ★ 1.2 | 906 | SKU-004195 |
| 4196 | Mega Automotive Product Advanced | Automotive | $685.29 | 353 | ★ 1.7 | 941 | SKU-004196 |
| 4197 | Mega Food & Grocery Product Advanced | Food & Grocery | $528.27 | 232 | ★ 1.7 | 492 | SKU-004197 |
| 4198 | Elite Home & Garden Product Max | Home & Garden | $564.50 | 302 | ★ 4.8 | 993 | SKU-004198 |
| 4199 | Deluxe Office Supplies Product Max | Office Supplies | $317.13 | 444 | ★ 2.5 | 87 | SKU-004199 |
| 4200 | Super Sports & Outdoors Product Plus | Sports & Outdoors | $288.33 | 462 | ★ 3.5 | 975 | SKU-004200 |
| 4201 | Deluxe Toys & Games Product Classic | Toys & Games | $818.56 | 232 | ★ 3.5 | 118 | SKU-004201 |
| 4202 | Standard Office Supplies Product Pro | Office Supplies | $899.58 | 271 | ★ 1.6 | 705 | SKU-004202 |
| 4203 | Ultra Clothing Product XL | Clothing | $482.97 | 199 | ★ 1.0 | 265 | SKU-004203 |
| 4204 | Elite Home & Garden Product Lite | Home & Garden | $690.39 | 492 | ★ 3.2 | 838 | SKU-004204 |
| 4205 | Ultra Office Supplies Product Advanced | Office Supplies | $835.10 | 359 | ★ 3.5 | 102 | SKU-004205 |
| 4206 | Professional Home & Garden Product XL | Home & Garden | $196.32 | 399 | ★ 2.3 | 979 | SKU-004206 |
| 4207 | Deluxe Health & Beauty Product XL | Health & Beauty | $577.89 | 186 | ★ 1.1 | 905 | SKU-004207 |
| 4208 | Elite Clothing Product 2024 | Clothing | $928.56 | 224 | ★ 4.0 | 778 | SKU-004208 |
| 4209 | Standard Toys & Games Product Plus | Toys & Games | $687.63 | 394 | ★ 2.1 | 165 | SKU-004209 |
| 4211 | Elite Clothing Product 2024 | Clothing | $56.90 | 264 | ★ 3.4 | 459 | SKU-004211 |
| 4212 | Mega Health & Beauty Product Max | Health & Beauty | $343.94 | 318 | ★ 3.7 | 270 | SKU-004212 |
| 4213 | Professional Electronics Product Advanced | Electronics | $262.17 | 31 | ★ 1.2 | 300 | SKU-004213 |
| 4214 | Mega Sports & Outdoors Product Advanced | Sports & Outdoors | $966.78 | 249 | ★ 1.2 | 224 | SKU-004214 |
| 4215 | Economy Clothing Product XL | Clothing | $153.39 | 242 | ★ 4.0 | 426 | SKU-004215 |
| 4216 | Super Home & Garden Product Lite | Home & Garden | $243.27 | 143 | ★ 1.3 | 734 | SKU-004216 |
| 4217 | Mega Books Product Advanced | Books | $726.46 | 56 | ★ 1.7 | 33 | SKU-004217 |
| 4218 | Standard Electronics Product 2024 | Electronics | $63.56 | 470 | ★ 4.9 | 808 | SKU-004218 |
// 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
};
}