Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4105 | Mega Sports & Outdoors Product Special Edition | Sports & Outdoors | $316.86 | 428 | ★ 3.4 | 575 | SKU-004105 |
| 4106 | Ultra Electronics Product Special Edition | Electronics | $907.10 | 67 | ★ 1.6 | 904 | SKU-004106 |
| 4108 | Mega Sports & Outdoors Product Lite | Sports & Outdoors | $724.81 | 62 | ★ 1.9 | 124 | SKU-004108 |
| 4110 | Elite Sports & Outdoors Product Classic | Sports & Outdoors | $171.44 | 134 | ★ 1.2 | 78 | SKU-004110 |
| 4111 | Mega Sports & Outdoors Product Mini | Sports & Outdoors | $398.87 | 10 | ★ 2.3 | 212 | SKU-004111 |
| 4112 | Standard Books Product 2024 | Books | $497.05 | 370 | ★ 2.5 | 763 | SKU-004112 |
| 4115 | Deluxe Automotive Product Special Edition | Automotive | $301.20 | 38 | ★ 4.5 | 20 | SKU-004115 |
| 4116 | Super Books Product Classic | Books | $494.41 | 84 | ★ 2.4 | 396 | SKU-004116 |
| 4117 | Ultra Books Product Lite | Books | $466.72 | 402 | ★ 2.3 | 964 | SKU-004117 |
| 4118 | Economy Toys & Games Product Classic | Toys & Games | $908.72 | 278 | ★ 3.5 | 964 | SKU-004118 |
| 4119 | Professional Clothing Product 2024 | Clothing | $210.36 | 381 | ★ 3.1 | 454 | SKU-004119 |
| 4120 | Pro Clothing Product Lite | Clothing | $327.20 | 213 | ★ 2.7 | 575 | SKU-004120 |
| 4121 | Ultra Home & Garden Product Special Edition | Home & Garden | $575.25 | 216 | ★ 4.4 | 756 | SKU-004121 |
| 4122 | Deluxe Office Supplies Product Advanced | Office Supplies | $142.06 | 271 | ★ 3.9 | 299 | SKU-004122 |
| 4123 | Elite Electronics Product 2024 | Electronics | $301.90 | 496 | ★ 1.8 | 330 | SKU-004123 |
| 4124 | Super Health & Beauty Product XL | Health & Beauty | $305.12 | 112 | ★ 1.0 | 627 | SKU-004124 |
| 4126 | Mega Office Supplies Product 2024 | Office Supplies | $599.45 | 450 | ★ 2.9 | 19 | SKU-004126 |
| 4127 | Deluxe Home & Garden Product XL | Home & Garden | $418.25 | 291 | ★ 2.1 | 583 | SKU-004127 |
| 4128 | Standard Electronics Product Lite | Electronics | $159.46 | 262 | ★ 3.8 | 496 | SKU-004128 |
| 4130 | Ultra Clothing Product Advanced | Clothing | $46.01 | 97 | ★ 3.5 | 747 | SKU-004130 |
| 4131 | Elite Sports & Outdoors Product 2024 | Sports & Outdoors | $627.02 | 37 | ★ 4.1 | 436 | SKU-004131 |
| 4132 | Economy Office Supplies Product Special Edition | Office Supplies | $844.60 | 189 | ★ 3.0 | 237 | SKU-004132 |
| 4133 | Super Health & Beauty Product Advanced | Health & Beauty | $745.20 | 445 | ★ 1.2 | 320 | SKU-004133 |
| 4134 | Mega Toys & Games Product Special Edition | Toys & Games | $971.52 | 199 | ★ 1.8 | 632 | SKU-004134 |
| 4135 | Professional Office Supplies Product 2024 | Office Supplies | $917.72 | 375 | ★ 2.8 | 855 | SKU-004135 |
| 4136 | Ultra Clothing Product XL | Clothing | $396.87 | 358 | ★ 1.1 | 352 | SKU-004136 |
| 4137 | Economy Health & Beauty Product Mini | Health & Beauty | $541.98 | 360 | ★ 2.6 | 21 | SKU-004137 |
| 4139 | Economy Electronics Product Plus | Electronics | $975.44 | 178 | ★ 1.8 | 261 | SKU-004139 |
| 4141 | Standard Home & Garden Product Plus | Home & Garden | $677.52 | 195 | ★ 1.4 | 719 | SKU-004141 |
| 4143 | Standard Books Product Mini | Books | $288.88 | 95 | ★ 3.6 | 988 | SKU-004143 |
| 4144 | Pro Automotive Product XL | Automotive | $713.15 | 339 | ★ 1.8 | 346 | SKU-004144 |
| 4145 | Elite Sports & Outdoors Product 2024 | Sports & Outdoors | $870.62 | 466 | ★ 3.6 | 839 | SKU-004145 |
| 4146 | Professional Food & Grocery Product 2024 | Food & Grocery | $215.83 | 355 | ★ 1.9 | 402 | SKU-004146 |
| 4148 | Deluxe Electronics Product Mini | Electronics | $946.31 | 247 | ★ 1.0 | 660 | SKU-004148 |
| 4149 | Elite Home & Garden Product Pro | Home & Garden | $973.12 | 243 | ★ 4.3 | 525 | SKU-004149 |
| 4150 | Elite Books Product Classic | Books | $422.84 | 24 | ★ 3.1 | 605 | SKU-004150 |
| 4151 | Deluxe Health & Beauty Product Advanced | Health & Beauty | $566.12 | 488 | ★ 2.6 | 342 | SKU-004151 |
| 4152 | Economy Electronics Product Special Edition | Electronics | $274.17 | 196 | ★ 4.0 | 691 | SKU-004152 |
| 4153 | Ultra Books Product Advanced | Books | $131.76 | 51 | ★ 4.2 | 11 | SKU-004153 |
| 4154 | Mega Books Product Lite | Books | $646.15 | 421 | ★ 2.9 | 952 | SKU-004154 |
| 4155 | Ultra Home & Garden Product 2024 | Home & Garden | $167.26 | 213 | ★ 3.8 | 272 | SKU-004155 |
| 4156 | Economy Clothing Product XL | Clothing | $482.05 | 131 | ★ 2.4 | 431 | SKU-004156 |
| 4157 | Mega Home & Garden Product Plus | Home & Garden | $177.67 | 426 | ★ 4.8 | 909 | SKU-004157 |
| 4158 | Standard Clothing Product Plus | Clothing | $341.16 | 18 | ★ 3.6 | 481 | SKU-004158 |
| 4159 | Super Clothing Product Advanced | Clothing | $907.68 | 121 | ★ 3.8 | 460 | SKU-004159 |
| 4160 | Pro Office Supplies Product Pro | Office Supplies | $12.52 | 133 | ★ 3.1 | 229 | SKU-004160 |
| 4162 | Standard Health & Beauty Product Max | Health & Beauty | $939.97 | 53 | ★ 3.2 | 779 | SKU-004162 |
| 4164 | Deluxe Sports & Outdoors Product XL | Sports & Outdoors | $935.52 | 115 | ★ 3.0 | 914 | SKU-004164 |
| 4165 | Professional Home & Garden Product Max | Home & Garden | $988.88 | 344 | ★ 1.0 | 398 | SKU-004165 |
| 4166 | Professional Books Product Lite | Books | $37.93 | 31 | ★ 2.6 | 576 | SKU-004166 |
// 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
};
}