Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 277 | Ultra Clothing Product Lite | Clothing | $885.80 | 223 | ★ 3.8 | 775 | SKU-000277 |
| 278 | Mega Toys & Games Product Plus | Toys & Games | $894.71 | 90 | ★ 2.3 | 435 | SKU-000278 |
| 279 | Deluxe Office Supplies Product Advanced | Office Supplies | $654.20 | 339 | ★ 2.2 | 546 | SKU-000279 |
| 281 | Pro Books Product Lite | Books | $761.35 | 316 | ★ 2.2 | 767 | SKU-000281 |
| 282 | Mega Health & Beauty Product Special Edition | Health & Beauty | $944.98 | 465 | ★ 3.5 | 884 | SKU-000282 |
| 283 | Premium Toys & Games Product Mini | Toys & Games | $20.29 | 258 | ★ 3.6 | 414 | SKU-000283 |
| 284 | Premium Books Product XL | Books | $18.53 | 129 | ★ 2.6 | 216 | SKU-000284 |
| 285 | Mega Clothing Product Classic | Clothing | $700.90 | 426 | ★ 3.1 | 789 | SKU-000285 |
| 286 | Ultra Office Supplies Product Special Edition | Office Supplies | $12.03 | 210 | ★ 4.2 | 795 | SKU-000286 |
| 287 | Ultra Books Product 2024 | Books | $852.90 | 471 | ★ 3.6 | 386 | SKU-000287 |
| 288 | Premium Food & Grocery Product XL | Food & Grocery | $927.15 | 349 | ★ 3.7 | 271 | SKU-000288 |
| 289 | Super Home & Garden Product Pro | Home & Garden | $96.43 | 462 | ★ 4.5 | 420 | SKU-000289 |
| 290 | Economy Clothing Product Classic | Clothing | $695.34 | 201 | ★ 3.5 | 218 | SKU-000290 |
| 291 | Standard Sports & Outdoors Product Special Edition | Sports & Outdoors | $806.66 | 136 | ★ 2.8 | 746 | SKU-000291 |
| 293 | Premium Food & Grocery Product 2024 | Food & Grocery | $162.70 | 150 | ★ 1.5 | 976 | SKU-000293 |
| 294 | Economy Health & Beauty Product Lite | Health & Beauty | $624.56 | 353 | ★ 3.7 | 754 | SKU-000294 |
| 295 | Mega Sports & Outdoors Product Advanced | Sports & Outdoors | $141.82 | 364 | ★ 3.7 | 998 | SKU-000295 |
| 296 | Standard Automotive Product Plus | Automotive | $748.85 | 180 | ★ 2.0 | 337 | SKU-000296 |
| 297 | Pro Home & Garden Product Classic | Home & Garden | $29.98 | 499 | ★ 1.5 | 703 | SKU-000297 |
| 299 | Standard Food & Grocery Product Max | Food & Grocery | $494.95 | 143 | ★ 4.1 | 490 | SKU-000299 |
| 300 | Economy Home & Garden Product Mini | Home & Garden | $37.33 | 432 | ★ 2.9 | 575 | SKU-000300 |
| 301 | Deluxe Home & Garden Product Pro | Home & Garden | $872.37 | 274 | ★ 4.0 | 161 | SKU-000301 |
| 302 | Standard Automotive Product Plus | Automotive | $437.46 | 222 | ★ 2.6 | 365 | SKU-000302 |
| 303 | Premium Health & Beauty Product Classic | Health & Beauty | $835.39 | 146 | ★ 3.2 | 495 | SKU-000303 |
| 304 | Standard Food & Grocery Product Advanced | Food & Grocery | $216.71 | 164 | ★ 1.3 | 774 | SKU-000304 |
| 305 | Super Books Product Max | Books | $396.40 | 455 | ★ 4.4 | 495 | SKU-000305 |
| 306 | Standard Clothing Product Classic | Clothing | $310.39 | 297 | ★ 3.7 | 427 | SKU-000306 |
| 307 | Economy Books Product Pro | Books | $650.32 | 377 | ★ 3.1 | 653 | SKU-000307 |
| 308 | Standard Clothing Product Special Edition | Clothing | $356.63 | 480 | ★ 2.8 | 66 | SKU-000308 |
| 309 | Standard Health & Beauty Product Pro | Health & Beauty | $197.23 | 135 | ★ 3.6 | 902 | SKU-000309 |
| 310 | Ultra Office Supplies Product Special Edition | Office Supplies | $992.30 | 277 | ★ 3.2 | 896 | SKU-000310 |
| 311 | Professional Home & Garden Product XL | Home & Garden | $824.56 | 61 | ★ 3.1 | 198 | SKU-000311 |
| 312 | Standard Health & Beauty Product Special Edition | Health & Beauty | $576.19 | 407 | ★ 3.7 | 323 | SKU-000312 |
| 313 | Super Automotive Product Classic | Automotive | $59.16 | 326 | ★ 1.5 | 142 | SKU-000313 |
| 314 | Ultra Office Supplies Product Advanced | Office Supplies | $118.54 | 214 | ★ 4.7 | 377 | SKU-000314 |
| 316 | Premium Sports & Outdoors Product Lite | Sports & Outdoors | $428.42 | 15 | ★ 3.5 | 627 | SKU-000316 |
| 317 | Pro Home & Garden Product Mini | Home & Garden | $921.48 | 387 | ★ 4.4 | 193 | SKU-000317 |
| 318 | Mega Electronics Product Pro | Electronics | $686.03 | 173 | ★ 3.0 | 774 | SKU-000318 |
| 319 | Standard Toys & Games Product 2024 | Toys & Games | $979.35 | 92 | ★ 1.8 | 865 | SKU-000319 |
| 321 | Professional Clothing Product Classic | Clothing | $51.91 | 449 | ★ 3.6 | 533 | SKU-000321 |
| 322 | Deluxe Books Product Plus | Books | $162.17 | 278 | ★ 3.2 | 231 | SKU-000322 |
| 323 | Professional Food & Grocery Product Special Edition | Food & Grocery | $867.27 | 283 | ★ 1.5 | 94 | SKU-000323 |
| 324 | Economy Books Product Special Edition | Books | $804.96 | 438 | ★ 2.2 | 302 | SKU-000324 |
| 325 | Pro Toys & Games Product Mini | Toys & Games | $960.75 | 127 | ★ 2.1 | 705 | SKU-000325 |
| 326 | Professional Home & Garden Product Mini | Home & Garden | $12.50 | 64 | ★ 1.8 | 889 | SKU-000326 |
| 327 | Ultra Sports & Outdoors Product 2024 | Sports & Outdoors | $785.18 | 244 | ★ 3.1 | 911 | SKU-000327 |
| 328 | Economy Toys & Games Product Plus | Toys & Games | $400.39 | 132 | ★ 3.9 | 482 | SKU-000328 |
| 329 | Professional Home & Garden Product Mini | Home & Garden | $952.44 | 144 | ★ 1.2 | 663 | SKU-000329 |
| 331 | Pro Home & Garden Product Max | Home & Garden | $840.52 | 467 | ★ 1.3 | 769 | SKU-000331 |
| 332 | Super Health & Beauty Product Advanced | Health & Beauty | $773.88 | 188 | ★ 3.1 | 558 | SKU-000332 |
// 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
};
}