Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2035 | Deluxe Home & Garden Product XL | Home & Garden | $457.89 | 201 | ★ 1.5 | 253 | SKU-002035 |
| 2036 | Professional Electronics Product Lite | Electronics | $389.02 | 152 | ★ 1.2 | 254 | SKU-002036 |
| 2037 | Professional Home & Garden Product XL | Home & Garden | $538.07 | 294 | ★ 2.4 | 292 | SKU-002037 |
| 2038 | Elite Sports & Outdoors Product Special Edition | Sports & Outdoors | $99.77 | 9 | ★ 2.4 | 347 | SKU-002038 |
| 2039 | Professional Electronics Product XL | Electronics | $419.57 | 76 | ★ 1.6 | 427 | SKU-002039 |
| 2040 | Pro Books Product Special Edition | Books | $598.35 | 275 | ★ 4.4 | 579 | SKU-002040 |
| 2041 | Pro Health & Beauty Product Max | Health & Beauty | $284.45 | 320 | ★ 4.8 | 495 | SKU-002041 |
| 2042 | Economy Sports & Outdoors Product Max | Sports & Outdoors | $647.07 | 408 | ★ 4.0 | 470 | SKU-002042 |
| 2043 | Ultra Electronics Product Advanced | Electronics | $896.58 | 222 | ★ 2.3 | 76 | SKU-002043 |
| 2044 | Economy Sports & Outdoors Product XL | Sports & Outdoors | $919.66 | 448 | ★ 1.0 | 229 | SKU-002044 |
| 2045 | Ultra Automotive Product 2024 | Automotive | $624.48 | 250 | ★ 1.9 | 477 | SKU-002045 |
| 2046 | Mega Sports & Outdoors Product 2024 | Sports & Outdoors | $861.96 | 166 | ★ 3.0 | 175 | SKU-002046 |
| 2047 | Pro Toys & Games Product Pro | Toys & Games | $202.22 | 118 | ★ 4.9 | 92 | SKU-002047 |
| 2048 | Premium Home & Garden Product Classic | Home & Garden | $457.71 | 301 | ★ 3.7 | 645 | SKU-002048 |
| 2049 | Ultra Clothing Product Plus | Clothing | $235.80 | 387 | ★ 4.1 | 587 | SKU-002049 |
| 2050 | Pro Books Product XL | Books | $342.76 | 492 | ★ 1.2 | 770 | SKU-002050 |
| 2051 | Standard Sports & Outdoors Product Advanced | Sports & Outdoors | $58.95 | 326 | ★ 1.6 | 334 | SKU-002051 |
| 2053 | Pro Toys & Games Product Max | Toys & Games | $680.25 | 293 | ★ 4.2 | 775 | SKU-002053 |
| 2054 | Mega Clothing Product Max | Clothing | $157.86 | 241 | ★ 1.4 | 203 | SKU-002054 |
| 2055 | Professional Clothing Product XL | Clothing | $323.65 | 314 | ★ 1.6 | 315 | SKU-002055 |
| 2056 | Economy Clothing Product Special Edition | Clothing | $743.65 | 393 | ★ 4.1 | 665 | SKU-002056 |
| 2057 | Mega Office Supplies Product 2024 | Office Supplies | $725.90 | 170 | ★ 3.2 | 623 | SKU-002057 |
| 2058 | Super Health & Beauty Product Special Edition | Health & Beauty | $557.24 | 251 | ★ 3.7 | 11 | SKU-002058 |
| 2059 | Super Health & Beauty Product Pro | Health & Beauty | $825.14 | 186 | ★ 4.0 | 843 | SKU-002059 |
| 2060 | Professional Health & Beauty Product 2024 | Health & Beauty | $983.22 | 87 | ★ 3.0 | 408 | SKU-002060 |
| 2061 | Elite Books Product Pro | Books | $575.90 | 247 | ★ 4.1 | 264 | SKU-002061 |
| 2062 | Premium Home & Garden Product Mini | Home & Garden | $90.32 | 149 | ★ 4.2 | 786 | SKU-002062 |
| 2063 | Mega Health & Beauty Product Mini | Health & Beauty | $664.61 | 150 | ★ 4.4 | 373 | SKU-002063 |
| 2064 | Super Sports & Outdoors Product Plus | Sports & Outdoors | $402.35 | 200 | ★ 1.0 | 483 | SKU-002064 |
| 2065 | Elite Office Supplies Product Special Edition | Office Supplies | $453.91 | 323 | ★ 4.9 | 301 | SKU-002065 |
| 2066 | Super Toys & Games Product Classic | Toys & Games | $696.71 | 493 | ★ 4.6 | 377 | SKU-002066 |
| 2067 | Economy Office Supplies Product 2024 | Office Supplies | $508.92 | 55 | ★ 3.5 | 394 | SKU-002067 |
| 2069 | Deluxe Electronics Product Plus | Electronics | $545.56 | 206 | ★ 3.5 | 636 | SKU-002069 |
| 2070 | Mega Health & Beauty Product Pro | Health & Beauty | $251.31 | 420 | ★ 2.0 | 566 | SKU-002070 |
| 2071 | Deluxe Office Supplies Product Classic | Office Supplies | $134.70 | 243 | ★ 2.4 | 391 | SKU-002071 |
| 2073 | Deluxe Sports & Outdoors Product Plus | Sports & Outdoors | $542.34 | 81 | ★ 2.0 | 563 | SKU-002073 |
| 2074 | Pro Home & Garden Product Advanced | Home & Garden | $438.45 | 343 | ★ 4.9 | 377 | SKU-002074 |
| 2075 | Elite Office Supplies Product Max | Office Supplies | $761.64 | 38 | ★ 4.5 | 163 | SKU-002075 |
| 2076 | Premium Sports & Outdoors Product Mini | Sports & Outdoors | $697.01 | 199 | ★ 1.2 | 402 | SKU-002076 |
| 2077 | Super Books Product XL | Books | $954.92 | 129 | ★ 1.2 | 712 | SKU-002077 |
| 2078 | Premium Sports & Outdoors Product Classic | Sports & Outdoors | $190.58 | 98 | ★ 3.1 | 709 | SKU-002078 |
| 2079 | Professional Toys & Games Product Pro | Toys & Games | $749.31 | 491 | ★ 3.0 | 417 | SKU-002079 |
| 2080 | Elite Food & Grocery Product Special Edition | Food & Grocery | $294.86 | 409 | ★ 1.4 | 670 | SKU-002080 |
| 2081 | Mega Office Supplies Product Plus | Office Supplies | $890.77 | 172 | ★ 1.7 | 928 | SKU-002081 |
| 2082 | Economy Electronics Product Plus | Electronics | $410.13 | 60 | ★ 1.5 | 891 | SKU-002082 |
| 2084 | Elite Health & Beauty Product Lite | Health & Beauty | $992.91 | 310 | ★ 2.3 | 915 | SKU-002084 |
| 2085 | Super Sports & Outdoors Product Special Edition | Sports & Outdoors | $507.41 | 157 | ★ 3.0 | 228 | SKU-002085 |
| 2086 | Premium Books Product Advanced | Books | $130.56 | 308 | ★ 2.2 | 334 | SKU-002086 |
| 2088 | Ultra Books Product Mini | Books | $424.98 | 222 | ★ 1.6 | 185 | SKU-002088 |
| 2089 | Elite Automotive Product 2024 | Automotive | $403.93 | 1 | ★ 3.6 | 962 | SKU-002089 |
// 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
};
}