Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2171 | Standard Books Product Lite | Books | $881.09 | 91 | ★ 4.4 | 100 | SKU-002171 |
| 2172 | Elite Automotive Product Special Edition | Automotive | $926.59 | 303 | ★ 3.5 | 105 | SKU-002172 |
| 2173 | Standard Health & Beauty Product 2024 | Health & Beauty | $84.94 | 198 | ★ 2.2 | 928 | SKU-002173 |
| 2174 | Standard Health & Beauty Product Special Edition | Health & Beauty | $153.10 | 337 | ★ 3.8 | 705 | SKU-002174 |
| 2175 | Economy Clothing Product Classic | Clothing | $811.81 | 173 | ★ 3.5 | 879 | SKU-002175 |
| 2177 | Standard Toys & Games Product Max | Toys & Games | $221.40 | 94 | ★ 3.2 | 699 | SKU-002177 |
| 2178 | Professional Sports & Outdoors Product Max | Sports & Outdoors | $691.22 | 283 | ★ 1.6 | 174 | SKU-002178 |
| 2179 | Standard Automotive Product Max | Automotive | $457.45 | 172 | ★ 2.9 | 959 | SKU-002179 |
| 2180 | Premium Books Product 2024 | Books | $57.58 | 297 | ★ 3.1 | 129 | SKU-002180 |
| 2181 | Elite Toys & Games Product Lite | Toys & Games | $724.39 | 30 | ★ 1.1 | 808 | SKU-002181 |
| 2182 | Elite Electronics Product Lite | Electronics | $328.42 | 314 | ★ 1.5 | 429 | SKU-002182 |
| 2183 | Mega Electronics Product Lite | Electronics | $95.87 | 123 | ★ 2.1 | 707 | SKU-002183 |
| 2184 | Professional Health & Beauty Product 2024 | Health & Beauty | $690.68 | 107 | ★ 4.9 | 989 | SKU-002184 |
| 2185 | Mega Clothing Product Special Edition | Clothing | $216.84 | 156 | ★ 2.6 | 542 | SKU-002185 |
| 2186 | Premium Automotive Product Advanced | Automotive | $664.64 | 205 | ★ 3.1 | 665 | SKU-002186 |
| 2187 | Pro Electronics Product Classic | Electronics | $74.23 | 115 | ★ 2.0 | 968 | SKU-002187 |
| 2188 | Economy Books Product Max | Books | $605.87 | 151 | ★ 4.9 | 356 | SKU-002188 |
| 2189 | Ultra Automotive Product Advanced | Automotive | $16.93 | 202 | ★ 2.8 | 292 | SKU-002189 |
| 2190 | Pro Books Product Mini | Books | $614.91 | 298 | ★ 4.3 | 726 | SKU-002190 |
| 2191 | Deluxe Clothing Product Max | Clothing | $306.84 | 227 | ★ 3.1 | 425 | SKU-002191 |
| 2192 | Ultra Electronics Product Pro | Electronics | $333.61 | 200 | ★ 2.7 | 807 | SKU-002192 |
| 2194 | Ultra Automotive Product Plus | Automotive | $527.25 | 64 | ★ 4.3 | 134 | SKU-002194 |
| 2195 | Professional Sports & Outdoors Product Pro | Sports & Outdoors | $665.41 | 85 | ★ 2.8 | 972 | SKU-002195 |
| 2196 | Ultra Automotive Product Max | Automotive | $677.21 | 211 | ★ 3.0 | 768 | SKU-002196 |
| 2197 | Premium Food & Grocery Product Advanced | Food & Grocery | $413.75 | 43 | ★ 3.1 | 182 | SKU-002197 |
// 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
};
}