Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1217 | Premium Health & Beauty Product Plus | Health & Beauty | $928.75 | 169 | ★ 4.1 | 153 | SKU-001217 |
| 1218 | Deluxe Electronics Product Plus | Electronics | $559.56 | 76 | ★ 4.3 | 851 | SKU-001218 |
| 1219 | Economy Books Product Plus | Books | $206.48 | 39 | ★ 1.7 | 555 | SKU-001219 |
| 1222 | Ultra Sports & Outdoors Product Classic | Sports & Outdoors | $81.48 | 161 | ★ 1.9 | 449 | SKU-001222 |
| 1223 | Premium Toys & Games Product Special Edition | Toys & Games | $161.40 | 344 | ★ 4.3 | 212 | SKU-001223 |
| 1224 | Super Electronics Product XL | Electronics | $457.61 | 384 | ★ 3.7 | 382 | SKU-001224 |
| 1225 | Elite Health & Beauty Product Pro | Health & Beauty | $17.24 | 374 | ★ 3.5 | 350 | SKU-001225 |
| 1226 | Mega Toys & Games Product Advanced | Toys & Games | $169.76 | 363 | ★ 2.8 | 918 | SKU-001226 |
| 1227 | Deluxe Automotive Product XL | Automotive | $657.02 | 70 | ★ 2.9 | 921 | SKU-001227 |
| 1228 | Pro Books Product Lite | Books | $944.62 | 203 | ★ 3.0 | 317 | SKU-001228 |
| 1229 | Super Books Product Special Edition | Books | $465.10 | 487 | ★ 4.8 | 208 | SKU-001229 |
| 1230 | Professional Toys & Games Product Plus | Toys & Games | $795.69 | 184 | ★ 4.4 | 991 | SKU-001230 |
| 1231 | Elite Home & Garden Product Classic | Home & Garden | $284.85 | 340 | ★ 4.7 | 30 | SKU-001231 |
| 1232 | Pro Health & Beauty Product Lite | Health & Beauty | $743.47 | 253 | ★ 4.8 | 748 | SKU-001232 |
| 1233 | Pro Food & Grocery Product Special Edition | Food & Grocery | $613.52 | 185 | ★ 2.2 | 71 | SKU-001233 |
| 1234 | Deluxe Home & Garden Product Plus | Home & Garden | $657.78 | 337 | ★ 4.6 | 247 | SKU-001234 |
| 1235 | Deluxe Food & Grocery Product Plus | Food & Grocery | $491.24 | 296 | ★ 4.4 | 955 | SKU-001235 |
| 1236 | Deluxe Automotive Product Classic | Automotive | $890.63 | 497 | ★ 1.0 | 296 | SKU-001236 |
| 1237 | Pro Books Product XL | Books | $866.71 | 332 | ★ 4.5 | 949 | SKU-001237 |
| 1239 | Elite Clothing Product XL | Clothing | $409.93 | 337 | ★ 2.0 | 531 | SKU-001239 |
| 1240 | Mega Toys & Games Product Advanced | Toys & Games | $259.66 | 377 | ★ 4.0 | 981 | SKU-001240 |
| 1241 | Pro Toys & Games Product Special Edition | Toys & Games | $591.07 | 33 | ★ 4.2 | 388 | SKU-001241 |
| 1242 | Elite Home & Garden Product Classic | Home & Garden | $576.58 | 279 | ★ 2.6 | 398 | SKU-001242 |
| 1243 | Ultra Office Supplies Product Special Edition | Office Supplies | $915.01 | 97 | ★ 2.8 | 390 | SKU-001243 |
| 1244 | Pro Health & Beauty Product Plus | Health & Beauty | $986.51 | 267 | ★ 3.7 | 595 | SKU-001244 |
// 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
};
}