Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4676 | Ultra Toys & Games Product Max | Toys & Games | $536.70 | 490 | ★ 1.5 | 892 | SKU-004676 |
| 4677 | Standard Electronics Product Mini | Electronics | $424.30 | 460 | ★ 3.9 | 639 | SKU-004677 |
| 4679 | Deluxe Home & Garden Product Mini | Home & Garden | $657.40 | 497 | ★ 2.4 | 349 | SKU-004679 |
| 4680 | Pro Sports & Outdoors Product Mini | Sports & Outdoors | $794.74 | 445 | ★ 1.4 | 297 | SKU-004680 |
| 4681 | Professional Electronics Product Special Edition | Electronics | $388.22 | 258 | ★ 4.9 | 255 | SKU-004681 |
| 4682 | Standard Home & Garden Product Special Edition | Home & Garden | $905.29 | 76 | ★ 3.0 | 411 | SKU-004682 |
| 4683 | Deluxe Toys & Games Product Classic | Toys & Games | $612.22 | 497 | ★ 1.2 | 205 | SKU-004683 |
| 4684 | Mega Electronics Product Mini | Electronics | $643.04 | 453 | ★ 3.3 | 367 | SKU-004684 |
| 4686 | Super Automotive Product Classic | Automotive | $11.08 | 415 | ★ 1.5 | 700 | SKU-004686 |
| 4687 | Deluxe Food & Grocery Product Mini | Food & Grocery | $272.28 | 282 | ★ 4.6 | 418 | SKU-004687 |
| 4688 | Ultra Sports & Outdoors Product Advanced | Sports & Outdoors | $741.61 | 462 | ★ 2.1 | 452 | SKU-004688 |
| 4689 | Ultra Health & Beauty Product XL | Health & Beauty | $212.12 | 29 | ★ 4.4 | 701 | SKU-004689 |
| 4690 | Pro Home & Garden Product Advanced | Home & Garden | $807.14 | 151 | ★ 4.8 | 791 | SKU-004690 |
| 4691 | Economy Electronics Product Special Edition | Electronics | $483.76 | 438 | ★ 3.3 | 222 | SKU-004691 |
| 4692 | Deluxe Health & Beauty Product Plus | Health & Beauty | $908.80 | 480 | ★ 1.9 | 622 | SKU-004692 |
| 4693 | Super Sports & Outdoors Product Advanced | Sports & Outdoors | $193.86 | 156 | ★ 4.4 | 145 | SKU-004693 |
| 4695 | Deluxe Books Product Advanced | Books | $667.75 | 108 | ★ 2.3 | 443 | SKU-004695 |
| 4696 | Pro Automotive Product Advanced | Automotive | $246.32 | 286 | ★ 2.1 | 498 | SKU-004696 |
| 4697 | Standard Food & Grocery Product Advanced | Food & Grocery | $445.26 | 230 | ★ 4.4 | 496 | SKU-004697 |
| 4698 | Deluxe Health & Beauty Product 2024 | Health & Beauty | $555.21 | 248 | ★ 4.1 | 817 | SKU-004698 |
| 4700 | Deluxe Office Supplies Product Lite | Office Supplies | $31.56 | 476 | ★ 3.0 | 357 | SKU-004700 |
| 4701 | Elite Automotive Product Special Edition | Automotive | $895.55 | 294 | ★ 3.3 | 673 | SKU-004701 |
| 4702 | Mega Books Product Mini | Books | $408.83 | 218 | ★ 3.7 | 149 | SKU-004702 |
| 4704 | Deluxe Books Product XL | Books | $31.82 | 469 | ★ 3.5 | 289 | SKU-004704 |
| 4705 | Economy Books Product 2024 | Books | $915.14 | 310 | ★ 1.0 | 942 | SKU-004705 |
| 4706 | Super Sports & Outdoors Product Special Edition | Sports & Outdoors | $602.19 | 450 | ★ 3.8 | 3 | SKU-004706 |
| 4707 | Standard Sports & Outdoors Product Lite | Sports & Outdoors | $189.82 | 494 | ★ 2.1 | 192 | SKU-004707 |
| 4708 | Premium Sports & Outdoors Product Lite | Sports & Outdoors | $840.01 | 273 | ★ 3.7 | 821 | SKU-004708 |
| 4709 | Mega Toys & Games Product Max | Toys & Games | $125.26 | 201 | ★ 1.1 | 29 | SKU-004709 |
| 4710 | Professional Office Supplies Product Advanced | Office Supplies | $149.69 | 308 | ★ 3.2 | 899 | SKU-004710 |
| 4711 | Mega Home & Garden Product Lite | Home & Garden | $221.93 | 470 | ★ 2.2 | 740 | SKU-004711 |
| 4712 | Premium Food & Grocery Product Pro | Food & Grocery | $396.46 | 209 | ★ 4.1 | 517 | SKU-004712 |
| 4713 | Premium Food & Grocery Product Pro | Food & Grocery | $972.70 | 181 | ★ 4.7 | 215 | SKU-004713 |
| 4714 | Pro Office Supplies Product Pro | Office Supplies | $986.02 | 462 | ★ 1.0 | 942 | SKU-004714 |
| 4716 | Pro Toys & Games Product Classic | Toys & Games | $678.48 | 248 | ★ 1.2 | 80 | SKU-004716 |
| 4718 | Deluxe Clothing Product Lite | Clothing | $659.70 | 471 | ★ 4.8 | 852 | SKU-004718 |
| 4719 | Super Electronics Product Advanced | Electronics | $766.67 | 304 | ★ 4.3 | 787 | SKU-004719 |
| 4720 | Pro Sports & Outdoors Product Advanced | Sports & Outdoors | $600.06 | 2 | ★ 1.2 | 547 | SKU-004720 |
| 4721 | Super Electronics Product Max | Electronics | $176.69 | 175 | ★ 4.4 | 941 | SKU-004721 |
| 4722 | Professional Food & Grocery Product Lite | Food & Grocery | $557.52 | 180 | ★ 1.8 | 477 | SKU-004722 |
| 4723 | Ultra Toys & Games Product Classic | Toys & Games | $125.70 | 23 | ★ 4.3 | 633 | SKU-004723 |
| 4724 | Ultra Automotive Product Mini | Automotive | $546.81 | 227 | ★ 3.9 | 122 | SKU-004724 |
| 4726 | Deluxe Home & Garden Product XL | Home & Garden | $587.04 | 89 | ★ 4.1 | 184 | SKU-004726 |
| 4727 | Pro Sports & Outdoors Product 2024 | Sports & Outdoors | $646.41 | 486 | ★ 3.0 | 905 | SKU-004727 |
| 4729 | Professional Toys & Games Product Special Edition | Toys & Games | $789.85 | 26 | ★ 3.5 | 209 | SKU-004729 |
| 4730 | Pro Clothing Product 2024 | Clothing | $258.54 | 440 | ★ 4.8 | 500 | SKU-004730 |
| 4733 | Deluxe Home & Garden Product Lite | Home & Garden | $312.34 | 270 | ★ 1.3 | 887 | SKU-004733 |
| 4734 | Professional Home & Garden Product Lite | Home & Garden | $84.19 | 375 | ★ 3.8 | 849 | SKU-004734 |
| 4735 | Mega Books Product Special Edition | Books | $112.97 | 435 | ★ 2.1 | 158 | SKU-004735 |
| 4737 | Deluxe Sports & Outdoors Product Mini | Sports & Outdoors | $863.24 | 279 | ★ 1.3 | 91 | SKU-004737 |
// 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
};
}