Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1 | Professional Books Product XL | Books | $300.20 | 159 | ★ 1.4 | 597 | SKU-000001 |
| 3 | Mega Home & Garden Product Lite | Home & Garden | $745.30 | 237 | ★ 2.4 | 931 | SKU-000003 |
| 4 | Super Home & Garden Product Lite | Home & Garden | $566.14 | 305 | ★ 1.9 | 762 | SKU-000004 |
| 5 | Economy Sports & Outdoors Product 2024 | Sports & Outdoors | $454.59 | 58 | ★ 4.9 | 875 | SKU-000005 |
| 6 | Ultra Office Supplies Product Classic | Office Supplies | $680.12 | 65 | ★ 4.8 | 458 | SKU-000006 |
| 7 | Premium Food & Grocery Product Plus | Food & Grocery | $893.65 | 58 | ★ 4.5 | 692 | SKU-000007 |
| 8 | Premium Toys & Games Product Advanced | Toys & Games | $777.64 | 269 | ★ 3.0 | 20 | SKU-000008 |
| 9 | Elite Office Supplies Product XL | Office Supplies | $524.92 | 447 | ★ 1.1 | 813 | SKU-000009 |
| 10 | Premium Sports & Outdoors Product Mini | Sports & Outdoors | $194.23 | 440 | ★ 2.5 | 512 | SKU-000010 |
| 11 | Super Automotive Product Plus | Automotive | $131.31 | 174 | ★ 2.1 | 182 | SKU-000011 |
| 12 | Super Home & Garden Product Pro | Home & Garden | $457.54 | 211 | ★ 4.3 | 283 | SKU-000012 |
| 13 | Premium Home & Garden Product Special Edition | Home & Garden | $63.63 | 356 | ★ 5.0 | 487 | SKU-000013 |
| 14 | Economy Food & Grocery Product Lite | Food & Grocery | $837.73 | 156 | ★ 2.0 | 775 | SKU-000014 |
| 15 | Mega Toys & Games Product Advanced | Toys & Games | $920.27 | 487 | ★ 5.0 | 840 | SKU-000015 |
| 17 | Standard Books Product Mini | Books | $775.00 | 108 | ★ 1.4 | 264 | SKU-000017 |
| 18 | Pro Sports & Outdoors Product Max | Sports & Outdoors | $218.35 | 248 | ★ 2.7 | 370 | SKU-000018 |
| 19 | Economy Office Supplies Product 2024 | Office Supplies | $619.90 | 158 | ★ 4.0 | 481 | SKU-000019 |
| 20 | Mega Health & Beauty Product Advanced | Health & Beauty | $378.20 | 25 | ★ 4.8 | 610 | SKU-000020 |
| 21 | Ultra Sports & Outdoors Product Max | Sports & Outdoors | $458.74 | 188 | ★ 1.8 | 477 | SKU-000021 |
| 22 | Professional Toys & Games Product Special Edition | Toys & Games | $555.99 | 272 | ★ 1.0 | 524 | SKU-000022 |
| 24 | Mega Books Product Plus | Books | $97.64 | 83 | ★ 1.4 | 673 | SKU-000024 |
| 25 | Super Clothing Product XL | Clothing | $607.42 | 230 | ★ 4.1 | 797 | SKU-000025 |
| 26 | Ultra Sports & Outdoors Product Advanced | Sports & Outdoors | $58.41 | 88 | ★ 3.8 | 618 | SKU-000026 |
| 27 | Professional Health & Beauty Product Advanced | Health & Beauty | $577.82 | 244 | ★ 4.7 | 853 | SKU-000027 |
| 28 | Mega Automotive Product Mini | Automotive | $199.65 | 251 | ★ 2.2 | 890 | SKU-000028 |
| 29 | Elite Sports & Outdoors Product 2024 | Sports & Outdoors | $148.04 | 128 | ★ 2.7 | 602 | SKU-000029 |
| 30 | Premium Electronics Product Pro | Electronics | $100.96 | 435 | ★ 2.2 | 553 | SKU-000030 |
| 31 | Mega Clothing Product 2024 | Clothing | $115.74 | 458 | ★ 4.8 | 163 | SKU-000031 |
| 32 | Pro Health & Beauty Product Classic | Health & Beauty | $996.94 | 321 | ★ 2.1 | 405 | SKU-000032 |
| 33 | Pro Sports & Outdoors Product Advanced | Sports & Outdoors | $736.58 | 432 | ★ 4.6 | 304 | SKU-000033 |
| 34 | Deluxe Books Product Pro | Books | $656.69 | 40 | ★ 2.9 | 600 | SKU-000034 |
| 35 | Ultra Sports & Outdoors Product XL | Sports & Outdoors | $976.95 | 253 | ★ 1.4 | 744 | SKU-000035 |
| 36 | Mega Books Product Advanced | Books | $972.71 | 135 | ★ 2.6 | 970 | SKU-000036 |
| 37 | Standard Home & Garden Product Advanced | Home & Garden | $753.83 | 219 | ★ 2.4 | 911 | SKU-000037 |
| 38 | Ultra Sports & Outdoors Product XL | Sports & Outdoors | $854.28 | 377 | ★ 4.0 | 463 | SKU-000038 |
| 39 | Premium Office Supplies Product Special Edition | Office Supplies | $416.94 | 389 | ★ 3.0 | 671 | SKU-000039 |
| 40 | Mega Food & Grocery Product Max | Food & Grocery | $783.32 | 334 | ★ 1.5 | 411 | SKU-000040 |
| 41 | Super Automotive Product Advanced | Automotive | $386.05 | 167 | ★ 2.3 | 737 | SKU-000041 |
| 43 | Ultra Sports & Outdoors Product Mini | Sports & Outdoors | $537.08 | 121 | ★ 2.7 | 151 | SKU-000043 |
| 44 | Standard Health & Beauty Product Max | Health & Beauty | $918.69 | 399 | ★ 4.2 | 798 | SKU-000044 |
| 45 | Ultra Home & Garden Product Special Edition | Home & Garden | $384.17 | 85 | ★ 2.5 | 213 | SKU-000045 |
| 46 | Premium Sports & Outdoors Product 2024 | Sports & Outdoors | $727.36 | 3 | ★ 3.6 | 769 | SKU-000046 |
| 47 | Deluxe Automotive Product Special Edition | Automotive | $252.24 | 430 | ★ 2.4 | 761 | SKU-000047 |
| 48 | Elite Clothing Product Max | Clothing | $517.25 | 321 | ★ 1.4 | 799 | SKU-000048 |
| 49 | Professional Electronics Product XL | Electronics | $186.36 | 322 | ★ 2.2 | 667 | SKU-000049 |
| 50 | Ultra Sports & Outdoors Product Max | Sports & Outdoors | $155.47 | 101 | ★ 1.8 | 487 | SKU-000050 |
| 52 | Economy Home & Garden Product 2024 | Home & Garden | $537.02 | 413 | ★ 4.6 | 611 | SKU-000052 |
| 53 | Standard Electronics Product XL | Electronics | $469.07 | 43 | ★ 4.0 | 613 | SKU-000053 |
| 54 | Economy Sports & Outdoors Product XL | Sports & Outdoors | $803.02 | 470 | ★ 2.7 | 437 | SKU-000054 |
| 56 | Super Automotive Product Pro | Automotive | $432.23 | 181 | ★ 2.1 | 516 | SKU-000056 |
// 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
};
}