Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 503 | Super Toys & Games Product Pro | Toys & Games | $942.15 | 264 | ★ 1.2 | 141 | SKU-000503 |
| 504 | Mega Food & Grocery Product Pro | Food & Grocery | $174.03 | 279 | ★ 1.4 | 947 | SKU-000504 |
| 505 | Premium Toys & Games Product Plus | Toys & Games | $132.44 | 344 | ★ 4.5 | 113 | SKU-000505 |
| 506 | Professional Toys & Games Product XL | Toys & Games | $357.14 | 218 | ★ 3.8 | 918 | SKU-000506 |
| 507 | Ultra Home & Garden Product 2024 | Home & Garden | $585.15 | 99 | ★ 1.9 | 471 | SKU-000507 |
| 508 | Deluxe Home & Garden Product Advanced | Home & Garden | $481.14 | 182 | ★ 1.8 | 611 | SKU-000508 |
| 509 | Premium Toys & Games Product Lite | Toys & Games | $281.77 | 492 | ★ 1.5 | 18 | SKU-000509 |
| 510 | Standard Toys & Games Product 2024 | Toys & Games | $644.04 | 446 | ★ 1.3 | 712 | SKU-000510 |
| 511 | Standard Office Supplies Product XL | Office Supplies | $994.62 | 60 | ★ 4.3 | 557 | SKU-000511 |
| 512 | Elite Sports & Outdoors Product Max | Sports & Outdoors | $534.38 | 84 | ★ 3.2 | 161 | SKU-000512 |
| 513 | Professional Automotive Product Advanced | Automotive | $730.03 | 220 | ★ 4.2 | 879 | SKU-000513 |
| 514 | Elite Office Supplies Product 2024 | Office Supplies | $37.88 | 267 | ★ 3.3 | 495 | SKU-000514 |
| 515 | Economy Electronics Product Pro | Electronics | $705.11 | 234 | ★ 3.4 | 93 | SKU-000515 |
| 516 | Economy Clothing Product 2024 | Clothing | $543.55 | 177 | ★ 4.5 | 343 | SKU-000516 |
| 517 | Pro Office Supplies Product Plus | Office Supplies | $142.26 | 17 | ★ 2.7 | 820 | SKU-000517 |
| 518 | Premium Automotive Product Pro | Automotive | $395.08 | 331 | ★ 1.3 | 65 | SKU-000518 |
| 519 | Super Books Product Lite | Books | $466.75 | 14 | ★ 2.2 | 929 | SKU-000519 |
| 520 | Standard Home & Garden Product XL | Home & Garden | $940.41 | 314 | ★ 2.6 | 50 | SKU-000520 |
| 521 | Pro Electronics Product XL | Electronics | $258.47 | 203 | ★ 1.9 | 163 | SKU-000521 |
| 523 | Elite Automotive Product Classic | Automotive | $263.42 | 277 | ★ 1.9 | 573 | SKU-000523 |
| 524 | Super Health & Beauty Product XL | Health & Beauty | $222.95 | 468 | ★ 4.3 | 214 | SKU-000524 |
| 525 | Pro Home & Garden Product Plus | Home & Garden | $138.42 | 211 | ★ 3.7 | 453 | SKU-000525 |
| 526 | Ultra Books Product XL | Books | $638.43 | 369 | ★ 2.9 | 931 | SKU-000526 |
| 527 | Elite Office Supplies Product Lite | Office Supplies | $876.91 | 470 | ★ 2.3 | 376 | SKU-000527 |
| 528 | Economy Sports & Outdoors Product Classic | Sports & Outdoors | $772.68 | 74 | ★ 1.8 | 868 | SKU-000528 |
| 529 | Ultra Automotive Product Plus | Automotive | $333.72 | 104 | ★ 3.7 | 205 | SKU-000529 |
| 530 | Economy Toys & Games Product Mini | Toys & Games | $344.11 | 234 | ★ 1.4 | 99 | SKU-000530 |
| 532 | Ultra Automotive Product Plus | Automotive | $232.07 | 236 | ★ 3.0 | 412 | SKU-000532 |
| 533 | Super Health & Beauty Product Lite | Health & Beauty | $888.41 | 470 | ★ 3.0 | 453 | SKU-000533 |
| 534 | Deluxe Books Product 2024 | Books | $991.87 | 408 | ★ 2.3 | 933 | SKU-000534 |
| 535 | Professional Sports & Outdoors Product XL | Sports & Outdoors | $177.24 | 110 | ★ 4.1 | 902 | SKU-000535 |
| 536 | Deluxe Clothing Product Pro | Clothing | $490.41 | 270 | ★ 3.0 | 872 | SKU-000536 |
| 537 | Economy Office Supplies Product XL | Office Supplies | $937.15 | 171 | ★ 1.3 | 951 | SKU-000537 |
| 538 | Super Toys & Games Product Advanced | Toys & Games | $544.09 | 174 | ★ 4.8 | 815 | SKU-000538 |
| 539 | Elite Home & Garden Product Classic | Home & Garden | $209.34 | 116 | ★ 4.3 | 852 | SKU-000539 |
| 540 | Standard Automotive Product Max | Automotive | $933.88 | 10 | ★ 3.2 | 172 | SKU-000540 |
| 541 | Pro Books Product XL | Books | $319.96 | 280 | ★ 4.2 | 349 | SKU-000541 |
| 542 | Super Electronics Product Mini | Electronics | $398.57 | 120 | ★ 2.1 | 480 | SKU-000542 |
| 543 | Ultra Health & Beauty Product Plus | Health & Beauty | $450.25 | 246 | ★ 1.8 | 61 | SKU-000543 |
| 544 | Standard Health & Beauty Product Max | Health & Beauty | $470.95 | 192 | ★ 2.0 | 577 | SKU-000544 |
| 545 | Professional Clothing Product Lite | Clothing | $99.37 | 90 | ★ 2.3 | 941 | SKU-000545 |
| 547 | Super Office Supplies Product Pro | Office Supplies | $533.41 | 111 | ★ 1.8 | 231 | SKU-000547 |
| 548 | Deluxe Sports & Outdoors Product 2024 | Sports & Outdoors | $339.49 | 138 | ★ 2.5 | 594 | SKU-000548 |
| 549 | Deluxe Books Product Classic | Books | $47.34 | 117 | ★ 1.3 | 468 | SKU-000549 |
| 550 | Super Office Supplies Product Plus | Office Supplies | $518.64 | 456 | ★ 2.0 | 113 | SKU-000550 |
| 551 | Professional Office Supplies Product Plus | Office Supplies | $191.93 | 368 | ★ 1.6 | 508 | SKU-000551 |
| 552 | Pro Food & Grocery Product Classic | Food & Grocery | $293.50 | 277 | ★ 1.3 | 956 | SKU-000552 |
| 553 | Pro Health & Beauty Product Max | Health & Beauty | $509.33 | 9 | ★ 4.4 | 450 | SKU-000553 |
| 554 | Ultra Automotive Product Lite | Automotive | $467.20 | 424 | ★ 3.3 | 288 | SKU-000554 |
| 555 | Standard Automotive Product Pro | Automotive | $654.94 | 468 | ★ 4.0 | 400 | SKU-000555 |
// 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
};
}