Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4566 | Ultra Books Product Pro | Books | $529.90 | 321 | ★ 4.0 | 0 | SKU-004566 |
| 4567 | Super Automotive Product Advanced | Automotive | $946.70 | 425 | ★ 3.8 | 211 | SKU-004567 |
| 4568 | Pro Health & Beauty Product Mini | Health & Beauty | $889.20 | 196 | ★ 1.4 | 609 | SKU-004568 |
| 4569 | Standard Books Product Plus | Books | $294.24 | 429 | ★ 3.7 | 728 | SKU-004569 |
| 4570 | Deluxe Sports & Outdoors Product Special Edition | Sports & Outdoors | $708.87 | 173 | ★ 3.2 | 851 | SKU-004570 |
| 4571 | Premium Electronics Product 2024 | Electronics | $271.77 | 333 | ★ 4.1 | 169 | SKU-004571 |
| 4572 | Deluxe Sports & Outdoors Product Lite | Sports & Outdoors | $737.68 | 139 | ★ 1.5 | 826 | SKU-004572 |
| 4573 | Mega Automotive Product Mini | Automotive | $922.91 | 170 | ★ 2.6 | 937 | SKU-004573 |
| 4574 | Pro Electronics Product Lite | Electronics | $211.43 | 492 | ★ 1.5 | 182 | SKU-004574 |
| 4575 | Premium Food & Grocery Product Plus | Food & Grocery | $883.44 | 273 | ★ 3.8 | 856 | SKU-004575 |
| 4576 | Deluxe Electronics Product Special Edition | Electronics | $280.06 | 486 | ★ 3.9 | 297 | SKU-004576 |
| 4577 | Deluxe Clothing Product Advanced | Clothing | $499.23 | 159 | ★ 4.7 | 91 | SKU-004577 |
| 4578 | Standard Automotive Product Plus | Automotive | $520.27 | 233 | ★ 1.9 | 174 | SKU-004578 |
| 4579 | Mega Books Product XL | Books | $879.12 | 48 | ★ 4.6 | 656 | SKU-004579 |
| 4580 | Professional Sports & Outdoors Product Lite | Sports & Outdoors | $484.96 | 30 | ★ 3.9 | 629 | SKU-004580 |
| 4581 | Standard Clothing Product Advanced | Clothing | $858.71 | 105 | ★ 5.0 | 464 | SKU-004581 |
| 4582 | Mega Electronics Product 2024 | Electronics | $324.14 | 493 | ★ 2.7 | 492 | SKU-004582 |
| 4583 | Standard Toys & Games Product Advanced | Toys & Games | $658.87 | 264 | ★ 5.0 | 283 | SKU-004583 |
| 4584 | Pro Health & Beauty Product Lite | Health & Beauty | $468.98 | 220 | ★ 2.9 | 313 | SKU-004584 |
| 4585 | Professional Sports & Outdoors Product Pro | Sports & Outdoors | $309.71 | 479 | ★ 3.4 | 306 | SKU-004585 |
| 4587 | Professional Sports & Outdoors Product Max | Sports & Outdoors | $917.01 | 208 | ★ 1.1 | 435 | SKU-004587 |
| 4588 | Pro Health & Beauty Product XL | Health & Beauty | $860.59 | 342 | ★ 3.3 | 14 | SKU-004588 |
| 4589 | Premium Automotive Product Max | Automotive | $416.91 | 116 | ★ 1.1 | 837 | SKU-004589 |
| 4590 | Economy Automotive Product Classic | Automotive | $818.26 | 81 | ★ 3.7 | 702 | SKU-004590 |
| 4592 | Professional Health & Beauty Product Special Edition | Health & Beauty | $277.79 | 132 | ★ 4.6 | 655 | SKU-004592 |
| 4593 | Ultra Electronics Product 2024 | Electronics | $679.52 | 463 | ★ 3.6 | 616 | SKU-004593 |
| 4594 | Deluxe Electronics Product Pro | Electronics | $943.76 | 164 | ★ 4.5 | 356 | SKU-004594 |
| 4595 | Ultra Automotive Product Advanced | Automotive | $561.09 | 440 | ★ 5.0 | 579 | SKU-004595 |
| 4596 | Professional Electronics Product Plus | Electronics | $555.98 | 428 | ★ 4.6 | 692 | SKU-004596 |
| 4597 | Elite Office Supplies Product Classic | Office Supplies | $567.04 | 211 | ★ 4.2 | 715 | SKU-004597 |
| 4598 | Elite Food & Grocery Product Max | Food & Grocery | $669.80 | 486 | ★ 1.1 | 624 | SKU-004598 |
| 4599 | Professional Sports & Outdoors Product Pro | Sports & Outdoors | $481.22 | 337 | ★ 2.9 | 201 | SKU-004599 |
| 4600 | Super Toys & Games Product Special Edition | Toys & Games | $875.72 | 454 | ★ 2.6 | 875 | SKU-004600 |
| 4601 | Ultra Food & Grocery Product Mini | Food & Grocery | $631.42 | 28 | ★ 1.7 | 184 | SKU-004601 |
| 4602 | Super Toys & Games Product Classic | Toys & Games | $776.50 | 473 | ★ 4.2 | 38 | SKU-004602 |
| 4604 | Standard Food & Grocery Product Plus | Food & Grocery | $622.71 | 147 | ★ 3.7 | 532 | SKU-004604 |
| 4605 | Premium Sports & Outdoors Product Plus | Sports & Outdoors | $15.75 | 388 | ★ 3.6 | 230 | SKU-004605 |
| 4607 | Deluxe Books Product Lite | Books | $222.92 | 283 | ★ 2.5 | 35 | SKU-004607 |
| 4608 | Ultra Books Product Mini | Books | $19.31 | 388 | ★ 4.1 | 68 | SKU-004608 |
| 4609 | Pro Home & Garden Product Pro | Home & Garden | $479.09 | 203 | ★ 1.4 | 955 | SKU-004609 |
| 4610 | Deluxe Books Product Plus | Books | $624.17 | 457 | ★ 1.1 | 334 | SKU-004610 |
| 4611 | Super Home & Garden Product Plus | Home & Garden | $419.35 | 50 | ★ 1.7 | 744 | SKU-004611 |
| 4612 | Mega Sports & Outdoors Product Classic | Sports & Outdoors | $356.06 | 24 | ★ 3.9 | 645 | SKU-004612 |
| 4613 | Pro Electronics Product Max | Electronics | $823.42 | 281 | ★ 2.0 | 804 | SKU-004613 |
| 4614 | Ultra Books Product Special Edition | Books | $434.52 | 22 | ★ 4.1 | 986 | SKU-004614 |
| 4615 | Pro Books Product XL | Books | $160.52 | 402 | ★ 4.6 | 117 | SKU-004615 |
| 4616 | Super Sports & Outdoors Product Mini | Sports & Outdoors | $919.71 | 122 | ★ 3.5 | 336 | SKU-004616 |
| 4617 | Ultra Automotive Product Mini | Automotive | $618.43 | 200 | ★ 4.2 | 992 | SKU-004617 |
| 4618 | Deluxe Sports & Outdoors Product Plus | Sports & Outdoors | $808.07 | 254 | ★ 2.3 | 17 | SKU-004618 |
| 4620 | Deluxe Clothing Product Pro | Clothing | $290.40 | 28 | ★ 2.4 | 240 | SKU-004620 |
// 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
};
}