Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2198 | Pro Food & Grocery Product Special Edition | Food & Grocery | $994.08 | 61 | ★ 3.3 | 260 | SKU-002198 |
| 2199 | Standard Office Supplies Product 2024 | Office Supplies | $893.09 | 82 | ★ 1.7 | 728 | SKU-002199 |
| 2200 | Deluxe Clothing Product Lite | Clothing | $96.49 | 227 | ★ 4.8 | 242 | SKU-002200 |
| 2201 | Economy Books Product Plus | Books | $12.32 | 385 | ★ 3.4 | 226 | SKU-002201 |
| 2202 | Economy Home & Garden Product Classic | Home & Garden | $516.91 | 344 | ★ 3.3 | 23 | SKU-002202 |
| 2204 | Economy Clothing Product XL | Clothing | $689.01 | 215 | ★ 4.9 | 575 | SKU-002204 |
| 2205 | Premium Food & Grocery Product 2024 | Food & Grocery | $588.05 | 264 | ★ 2.9 | 330 | SKU-002205 |
| 2206 | Standard Books Product Advanced | Books | $129.03 | 322 | ★ 1.2 | 680 | SKU-002206 |
| 2207 | Standard Home & Garden Product Lite | Home & Garden | $805.36 | 30 | ★ 3.8 | 892 | SKU-002207 |
| 2208 | Ultra Health & Beauty Product Lite | Health & Beauty | $969.47 | 263 | ★ 2.5 | 792 | SKU-002208 |
| 2209 | Economy Health & Beauty Product Plus | Health & Beauty | $808.24 | 376 | ★ 3.6 | 933 | SKU-002209 |
| 2210 | Standard Automotive Product Classic | Automotive | $71.57 | 58 | ★ 4.1 | 457 | SKU-002210 |
| 2212 | Standard Automotive Product Advanced | Automotive | $476.15 | 278 | ★ 2.5 | 589 | SKU-002212 |
| 2213 | Elite Books Product Max | Books | $193.21 | 194 | ★ 2.9 | 498 | SKU-002213 |
| 2214 | Professional Books Product Pro | Books | $17.93 | 259 | ★ 4.9 | 199 | SKU-002214 |
| 2215 | Economy Toys & Games Product Pro | Toys & Games | $130.86 | 298 | ★ 1.5 | 444 | SKU-002215 |
| 2216 | Deluxe Automotive Product Mini | Automotive | $999.12 | 62 | ★ 4.2 | 877 | SKU-002216 |
| 2217 | Economy Automotive Product Plus | Automotive | $310.72 | 146 | ★ 1.4 | 758 | SKU-002217 |
| 2218 | Deluxe Automotive Product Pro | Automotive | $168.61 | 382 | ★ 3.6 | 171 | SKU-002218 |
| 2219 | Elite Books Product Lite | Books | $986.07 | 404 | ★ 4.5 | 497 | SKU-002219 |
| 2220 | Standard Toys & Games Product XL | Toys & Games | $125.55 | 307 | ★ 2.2 | 694 | SKU-002220 |
| 2221 | Mega Clothing Product XL | Clothing | $631.89 | 477 | ★ 2.4 | 265 | SKU-002221 |
| 2222 | Professional Home & Garden Product XL | Home & Garden | $509.03 | 97 | ★ 3.0 | 292 | SKU-002222 |
| 2223 | Ultra Food & Grocery Product Classic | Food & Grocery | $201.94 | 240 | ★ 1.1 | 744 | SKU-002223 |
| 2224 | Deluxe Home & Garden Product Mini | Home & Garden | $778.33 | 101 | ★ 1.3 | 781 | SKU-002224 |
| 2225 | Super Food & Grocery Product Special Edition | Food & Grocery | $533.74 | 153 | ★ 2.1 | 432 | SKU-002225 |
| 2226 | Professional Health & Beauty Product Max | Health & Beauty | $439.81 | 141 | ★ 3.0 | 319 | SKU-002226 |
| 2227 | Standard Automotive Product XL | Automotive | $704.21 | 90 | ★ 4.2 | 484 | SKU-002227 |
| 2228 | Mega Books Product Pro | Books | $854.18 | 61 | ★ 1.3 | 401 | SKU-002228 |
| 2229 | Deluxe Books Product XL | Books | $343.22 | 229 | ★ 2.0 | 447 | SKU-002229 |
| 2230 | Economy Electronics Product Advanced | Electronics | $58.46 | 371 | ★ 4.8 | 504 | SKU-002230 |
| 2231 | Economy Home & Garden Product Mini | Home & Garden | $262.96 | 345 | ★ 2.1 | 343 | SKU-002231 |
| 2232 | Premium Books Product Classic | Books | $671.77 | 313 | ★ 5.0 | 377 | SKU-002232 |
| 2233 | Super Health & Beauty Product Plus | Health & Beauty | $815.74 | 9 | ★ 1.5 | 327 | SKU-002233 |
| 2234 | Pro Food & Grocery Product Plus | Food & Grocery | $541.44 | 324 | ★ 2.4 | 4 | SKU-002234 |
| 2235 | Ultra Health & Beauty Product Lite | Health & Beauty | $475.16 | 464 | ★ 2.4 | 412 | SKU-002235 |
| 2236 | Professional Health & Beauty Product Plus | Health & Beauty | $469.00 | 442 | ★ 2.7 | 944 | SKU-002236 |
| 2237 | Ultra Sports & Outdoors Product Advanced | Sports & Outdoors | $555.86 | 347 | ★ 3.4 | 930 | SKU-002237 |
| 2238 | Deluxe Health & Beauty Product Plus | Health & Beauty | $293.80 | 249 | ★ 1.3 | 15 | SKU-002238 |
| 2239 | Standard Home & Garden Product XL | Home & Garden | $572.57 | 189 | ★ 1.5 | 638 | SKU-002239 |
| 2240 | Deluxe Electronics Product Advanced | Electronics | $267.39 | 178 | ★ 2.3 | 431 | SKU-002240 |
| 2241 | Mega Toys & Games Product Plus | Toys & Games | $98.77 | 397 | ★ 1.6 | 884 | SKU-002241 |
| 2242 | Ultra Clothing Product Advanced | Clothing | $290.54 | 459 | ★ 2.0 | 307 | SKU-002242 |
| 2243 | Elite Sports & Outdoors Product Mini | Sports & Outdoors | $619.73 | 175 | ★ 2.2 | 946 | SKU-002243 |
| 2244 | Economy Food & Grocery Product Special Edition | Food & Grocery | $431.40 | 27 | ★ 4.4 | 919 | SKU-002244 |
| 2245 | Economy Clothing Product Advanced | Clothing | $108.17 | 89 | ★ 3.9 | 974 | SKU-002245 |
| 2246 | Professional Electronics Product Special Edition | Electronics | $362.49 | 181 | ★ 1.1 | 244 | SKU-002246 |
| 2247 | Pro Electronics Product XL | Electronics | $334.52 | 479 | ★ 4.1 | 183 | SKU-002247 |
| 2248 | Economy Electronics Product Advanced | Electronics | $815.01 | 55 | ★ 1.5 | 634 | SKU-002248 |
| 2249 | Pro Sports & Outdoors Product Mini | Sports & Outdoors | $883.49 | 280 | ★ 2.8 | 559 | SKU-002249 |
// 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
};
}