Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 387 | Pro Toys & Games Product 2024 | Toys & Games | $483.63 | 115 | ★ 3.2 | 861 | SKU-000387 |
| 388 | Standard Books Product Lite | Books | $48.48 | 234 | ★ 2.4 | 502 | SKU-000388 |
| 389 | Elite Automotive Product 2024 | Automotive | $197.91 | 44 | ★ 2.0 | 254 | SKU-000389 |
| 390 | Standard Toys & Games Product Lite | Toys & Games | $42.37 | 446 | ★ 3.7 | 310 | SKU-000390 |
| 391 | Premium Home & Garden Product Lite | Home & Garden | $339.48 | 29 | ★ 2.7 | 787 | SKU-000391 |
| 392 | Elite Books Product Plus | Books | $890.43 | 246 | ★ 1.2 | 382 | SKU-000392 |
| 393 | Ultra Books Product Max | Books | $111.91 | 486 | ★ 3.3 | 996 | SKU-000393 |
| 394 | Pro Books Product Lite | Books | $325.41 | 32 | ★ 2.6 | 730 | SKU-000394 |
| 395 | Deluxe Office Supplies Product Pro | Office Supplies | $714.44 | 153 | ★ 3.3 | 47 | SKU-000395 |
| 399 | Premium Toys & Games Product Mini | Toys & Games | $856.60 | 440 | ★ 2.0 | 570 | SKU-000399 |
| 400 | Deluxe Home & Garden Product Advanced | Home & Garden | $68.22 | 366 | ★ 3.0 | 416 | SKU-000400 |
| 401 | Premium Food & Grocery Product Pro | Food & Grocery | $467.15 | 323 | ★ 3.9 | 396 | SKU-000401 |
| 402 | Professional Food & Grocery Product Max | Food & Grocery | $510.05 | 143 | ★ 2.0 | 211 | SKU-000402 |
| 403 | Deluxe Health & Beauty Product Pro | Health & Beauty | $691.46 | 110 | ★ 1.9 | 526 | SKU-000403 |
| 404 | Premium Office Supplies Product Advanced | Office Supplies | $277.60 | 8 | ★ 3.9 | 423 | SKU-000404 |
| 405 | Premium Food & Grocery Product Plus | Food & Grocery | $886.83 | 379 | ★ 4.1 | 527 | SKU-000405 |
| 406 | Ultra Health & Beauty Product XL | Health & Beauty | $70.20 | 52 | ★ 1.4 | 345 | SKU-000406 |
| 407 | Standard Office Supplies Product Mini | Office Supplies | $87.39 | 220 | ★ 2.0 | 669 | SKU-000407 |
| 408 | Professional Clothing Product XL | Clothing | $286.74 | 81 | ★ 1.7 | 168 | SKU-000408 |
| 409 | Ultra Electronics Product Max | Electronics | $131.40 | 205 | ★ 2.3 | 110 | SKU-000409 |
| 410 | Economy Books Product Mini | Books | $736.19 | 421 | ★ 4.4 | 629 | SKU-000410 |
| 411 | Super Books Product Lite | Books | $70.77 | 468 | ★ 4.0 | 397 | SKU-000411 |
| 412 | Ultra Home & Garden Product Classic | Home & Garden | $608.49 | 132 | ★ 3.6 | 734 | SKU-000412 |
| 413 | Economy Electronics Product Plus | Electronics | $368.76 | 258 | ★ 2.7 | 922 | SKU-000413 |
| 414 | Elite Electronics Product XL | Electronics | $788.26 | 404 | ★ 2.6 | 431 | SKU-000414 |
| 415 | Deluxe Office Supplies Product Classic | Office Supplies | $380.05 | 290 | ★ 2.3 | 747 | SKU-000415 |
| 417 | Premium Health & Beauty Product 2024 | Health & Beauty | $962.68 | 381 | ★ 3.7 | 18 | SKU-000417 |
| 418 | Super Office Supplies Product XL | Office Supplies | $526.83 | 423 | ★ 1.5 | 881 | SKU-000418 |
| 419 | Economy Electronics Product Special Edition | Electronics | $715.88 | 361 | ★ 4.3 | 972 | SKU-000419 |
| 421 | Economy Home & Garden Product Plus | Home & Garden | $996.91 | 340 | ★ 1.4 | 978 | SKU-000421 |
| 422 | Standard Toys & Games Product Classic | Toys & Games | $847.38 | 102 | ★ 1.0 | 691 | SKU-000422 |
| 424 | Standard Automotive Product Pro | Automotive | $403.93 | 168 | ★ 3.2 | 757 | SKU-000424 |
| 426 | Elite Clothing Product Advanced | Clothing | $354.63 | 216 | ★ 2.7 | 320 | SKU-000426 |
| 427 | Elite Toys & Games Product XL | Toys & Games | $101.48 | 204 | ★ 1.8 | 600 | SKU-000427 |
| 428 | Deluxe Home & Garden Product Advanced | Home & Garden | $791.45 | 257 | ★ 4.9 | 236 | SKU-000428 |
| 429 | Elite Automotive Product Pro | Automotive | $525.05 | 446 | ★ 1.4 | 37 | SKU-000429 |
| 430 | Pro Electronics Product Lite | Electronics | $496.63 | 469 | ★ 3.6 | 982 | SKU-000430 |
| 431 | Ultra Sports & Outdoors Product Advanced | Sports & Outdoors | $183.86 | 413 | ★ 2.9 | 85 | SKU-000431 |
| 432 | Mega Health & Beauty Product Advanced | Health & Beauty | $554.43 | 164 | ★ 3.1 | 912 | SKU-000432 |
| 433 | Pro Home & Garden Product Mini | Home & Garden | $950.25 | 376 | ★ 4.3 | 635 | SKU-000433 |
| 434 | Premium Office Supplies Product Classic | Office Supplies | $848.24 | 82 | ★ 3.0 | 847 | SKU-000434 |
| 435 | Professional Food & Grocery Product Lite | Food & Grocery | $96.80 | 219 | ★ 2.8 | 279 | SKU-000435 |
| 436 | Mega Food & Grocery Product Special Edition | Food & Grocery | $657.22 | 438 | ★ 1.5 | 843 | SKU-000436 |
| 438 | Mega Sports & Outdoors Product Max | Sports & Outdoors | $238.80 | 182 | ★ 1.0 | 324 | SKU-000438 |
| 440 | Premium Health & Beauty Product Advanced | Health & Beauty | $753.49 | 139 | ★ 1.9 | 412 | SKU-000440 |
| 443 | Standard Electronics Product Special Edition | Electronics | $575.64 | 105 | ★ 2.7 | 720 | SKU-000443 |
| 444 | Premium Clothing Product Advanced | Clothing | $645.05 | 446 | ★ 4.4 | 624 | SKU-000444 |
| 445 | Standard Sports & Outdoors Product Special Edition | Sports & Outdoors | $654.70 | 284 | ★ 4.6 | 251 | SKU-000445 |
| 446 | Standard Home & Garden Product Max | Home & Garden | $814.15 | 411 | ★ 3.8 | 894 | SKU-000446 |
| 447 | Super Health & Beauty Product Max | Health & Beauty | $890.18 | 322 | ★ 4.1 | 921 | SKU-000447 |
// 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
};
}