Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4193 | Economy Books Product Max | Books | $301.10 | 457 | ★ 3.2 | 524 | SKU-004193 |
| 4194 | Standard Books Product Mini | Books | $791.36 | 112 | ★ 1.1 | 101 | SKU-004194 |
| 4195 | Premium Toys & Games Product Special Edition | Toys & Games | $563.26 | 381 | ★ 1.2 | 906 | SKU-004195 |
| 4196 | Mega Automotive Product Advanced | Automotive | $685.29 | 353 | ★ 1.7 | 941 | SKU-004196 |
| 4197 | Mega Food & Grocery Product Advanced | Food & Grocery | $528.27 | 232 | ★ 1.7 | 492 | SKU-004197 |
| 4198 | Elite Home & Garden Product Max | Home & Garden | $564.50 | 302 | ★ 4.8 | 993 | SKU-004198 |
| 4199 | Deluxe Office Supplies Product Max | Office Supplies | $317.13 | 444 | ★ 2.5 | 87 | SKU-004199 |
| 4200 | Super Sports & Outdoors Product Plus | Sports & Outdoors | $288.33 | 462 | ★ 3.5 | 975 | SKU-004200 |
| 4201 | Deluxe Toys & Games Product Classic | Toys & Games | $818.56 | 232 | ★ 3.5 | 118 | SKU-004201 |
| 4202 | Standard Office Supplies Product Pro | Office Supplies | $899.58 | 271 | ★ 1.6 | 705 | SKU-004202 |
| 4203 | Ultra Clothing Product XL | Clothing | $482.97 | 199 | ★ 1.0 | 265 | SKU-004203 |
| 4204 | Elite Home & Garden Product Lite | Home & Garden | $690.39 | 492 | ★ 3.2 | 838 | SKU-004204 |
| 4205 | Ultra Office Supplies Product Advanced | Office Supplies | $835.10 | 359 | ★ 3.5 | 102 | SKU-004205 |
| 4206 | Professional Home & Garden Product XL | Home & Garden | $196.32 | 399 | ★ 2.3 | 979 | SKU-004206 |
| 4207 | Deluxe Health & Beauty Product XL | Health & Beauty | $577.89 | 186 | ★ 1.1 | 905 | SKU-004207 |
| 4208 | Elite Clothing Product 2024 | Clothing | $928.56 | 224 | ★ 4.0 | 778 | SKU-004208 |
| 4209 | Standard Toys & Games Product Plus | Toys & Games | $687.63 | 394 | ★ 2.1 | 165 | SKU-004209 |
| 4211 | Elite Clothing Product 2024 | Clothing | $56.90 | 264 | ★ 3.4 | 459 | SKU-004211 |
| 4212 | Mega Health & Beauty Product Max | Health & Beauty | $343.94 | 318 | ★ 3.7 | 270 | SKU-004212 |
| 4213 | Professional Electronics Product Advanced | Electronics | $262.17 | 31 | ★ 1.2 | 300 | SKU-004213 |
| 4214 | Mega Sports & Outdoors Product Advanced | Sports & Outdoors | $966.78 | 249 | ★ 1.2 | 224 | SKU-004214 |
| 4215 | Economy Clothing Product XL | Clothing | $153.39 | 242 | ★ 4.0 | 426 | SKU-004215 |
| 4216 | Super Home & Garden Product Lite | Home & Garden | $243.27 | 143 | ★ 1.3 | 734 | SKU-004216 |
| 4217 | Mega Books Product Advanced | Books | $726.46 | 56 | ★ 1.7 | 33 | SKU-004217 |
| 4218 | Standard Electronics Product 2024 | Electronics | $63.56 | 470 | ★ 4.9 | 808 | SKU-004218 |
// 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
};
}