Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4957 | Deluxe Food & Grocery Product 2024 | Food & Grocery | $678.99 | 491 | ★ 3.2 | 205 | SKU-004957 |
| 4958 | Premium Food & Grocery Product Advanced | Food & Grocery | $629.43 | 114 | ★ 4.2 | 600 | SKU-004958 |
| 4959 | Mega Clothing Product Mini | Clothing | $973.57 | 318 | ★ 3.9 | 835 | SKU-004959 |
| 4960 | Standard Books Product 2024 | Books | $336.54 | 343 | ★ 4.2 | 699 | SKU-004960 |
| 4961 | Mega Food & Grocery Product Classic | Food & Grocery | $997.32 | 341 | ★ 3.1 | 617 | SKU-004961 |
| 4962 | Economy Books Product Special Edition | Books | $301.14 | 189 | ★ 3.6 | 352 | SKU-004962 |
| 4963 | Economy Health & Beauty Product Plus | Health & Beauty | $961.91 | 350 | ★ 3.6 | 261 | SKU-004963 |
| 4964 | Premium Books Product Classic | Books | $359.84 | 356 | ★ 1.7 | 386 | SKU-004964 |
| 4965 | Standard Electronics Product Lite | Electronics | $550.59 | 345 | ★ 4.4 | 526 | SKU-004965 |
| 4966 | Professional Health & Beauty Product Special Edition | Health & Beauty | $371.03 | 260 | ★ 4.8 | 769 | SKU-004966 |
| 4967 | Premium Food & Grocery Product 2024 | Food & Grocery | $28.22 | 51 | ★ 3.1 | 143 | SKU-004967 |
| 4968 | Pro Automotive Product Plus | Automotive | $818.90 | 91 | ★ 2.2 | 649 | SKU-004968 |
| 4969 | Pro Food & Grocery Product Classic | Food & Grocery | $615.66 | 369 | ★ 3.3 | 638 | SKU-004969 |
| 4970 | Standard Books Product XL | Books | $908.11 | 290 | ★ 2.4 | 385 | SKU-004970 |
| 4971 | Deluxe Books Product Lite | Books | $386.52 | 69 | ★ 1.8 | 456 | SKU-004971 |
| 4972 | Super Sports & Outdoors Product 2024 | Sports & Outdoors | $836.81 | 76 | ★ 2.2 | 15 | SKU-004972 |
| 4973 | Premium Home & Garden Product Max | Home & Garden | $83.06 | 72 | ★ 3.4 | 801 | SKU-004973 |
| 4974 | Super Sports & Outdoors Product Plus | Sports & Outdoors | $321.24 | 196 | ★ 2.8 | 523 | SKU-004974 |
| 4975 | Elite Books Product 2024 | Books | $23.54 | 403 | ★ 4.8 | 434 | SKU-004975 |
| 4976 | Deluxe Home & Garden Product 2024 | Home & Garden | $137.57 | 461 | ★ 3.8 | 648 | SKU-004976 |
| 4977 | Mega Office Supplies Product Classic | Office Supplies | $876.34 | 49 | ★ 4.8 | 0 | SKU-004977 |
| 4978 | Premium Toys & Games Product Classic | Toys & Games | $44.01 | 316 | ★ 4.8 | 422 | SKU-004978 |
| 4979 | Professional Food & Grocery Product 2024 | Food & Grocery | $823.63 | 332 | ★ 2.6 | 192 | SKU-004979 |
| 4981 | Mega Home & Garden Product Advanced | Home & Garden | $422.13 | 292 | ★ 4.0 | 180 | SKU-004981 |
| 4982 | Ultra Office Supplies Product Plus | Office Supplies | $760.59 | 470 | ★ 2.8 | 869 | SKU-004982 |
// 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
};
}