Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4047 | Ultra Books Product Max | Books | $685.49 | 218 | ★ 4.9 | 301 | SKU-004047 |
| 4048 | Standard Sports & Outdoors Product Classic | Sports & Outdoors | $131.91 | 134 | ★ 3.5 | 396 | SKU-004048 |
| 4049 | Ultra Books Product XL | Books | $888.95 | 189 | ★ 1.8 | 418 | SKU-004049 |
| 4050 | Mega Health & Beauty Product Plus | Health & Beauty | $340.92 | 86 | ★ 4.0 | 612 | SKU-004050 |
| 4051 | Premium Health & Beauty Product Pro | Health & Beauty | $489.14 | 420 | ★ 1.5 | 211 | SKU-004051 |
| 4052 | Economy Health & Beauty Product Special Edition | Health & Beauty | $33.55 | 104 | ★ 5.0 | 443 | SKU-004052 |
| 4053 | Economy Automotive Product Plus | Automotive | $105.50 | 131 | ★ 1.5 | 534 | SKU-004053 |
| 4054 | Economy Toys & Games Product Pro | Toys & Games | $417.83 | 216 | ★ 2.2 | 801 | SKU-004054 |
| 4055 | Ultra Sports & Outdoors Product Special Edition | Sports & Outdoors | $887.67 | 83 | ★ 4.6 | 176 | SKU-004055 |
| 4056 | Professional Books Product Mini | Books | $245.67 | 39 | ★ 1.9 | 925 | SKU-004056 |
| 4057 | Premium Office Supplies Product Lite | Office Supplies | $723.68 | 159 | ★ 2.8 | 207 | SKU-004057 |
| 4058 | Economy Toys & Games Product Mini | Toys & Games | $118.17 | 227 | ★ 1.6 | 186 | SKU-004058 |
| 4059 | Professional Food & Grocery Product Max | Food & Grocery | $456.37 | 110 | ★ 2.3 | 116 | SKU-004059 |
| 4060 | Super Toys & Games Product Advanced | Toys & Games | $312.17 | 78 | ★ 1.0 | 921 | SKU-004060 |
| 4061 | Deluxe Home & Garden Product Plus | Home & Garden | $649.64 | 333 | ★ 2.8 | 114 | SKU-004061 |
| 4062 | Economy Food & Grocery Product Mini | Food & Grocery | $806.21 | 5 | ★ 3.8 | 1 | SKU-004062 |
| 4063 | Mega Books Product Pro | Books | $312.69 | 492 | ★ 4.0 | 655 | SKU-004063 |
| 4064 | Professional Toys & Games Product XL | Toys & Games | $339.48 | 303 | ★ 2.3 | 792 | SKU-004064 |
| 4065 | Mega Toys & Games Product 2024 | Toys & Games | $678.40 | 190 | ★ 2.7 | 235 | SKU-004065 |
| 4066 | Elite Electronics Product XL | Electronics | $440.57 | 159 | ★ 4.9 | 453 | SKU-004066 |
| 4069 | Standard Health & Beauty Product Max | Health & Beauty | $570.02 | 432 | ★ 4.3 | 737 | SKU-004069 |
| 4070 | Professional Food & Grocery Product XL | Food & Grocery | $789.04 | 12 | ★ 4.8 | 106 | SKU-004070 |
| 4071 | Elite Home & Garden Product Special Edition | Home & Garden | $322.50 | 176 | ★ 4.0 | 837 | SKU-004071 |
| 4072 | Super Books Product Advanced | Books | $750.37 | 449 | ★ 4.1 | 198 | SKU-004072 |
| 4073 | Ultra Automotive Product Advanced | Automotive | $65.65 | 340 | ★ 1.9 | 424 | SKU-004073 |
// 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
};
}