Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1892 | Deluxe Food & Grocery Product Max | Food & Grocery | $104.70 | 494 | ★ 4.2 | 646 | SKU-001892 |
| 1893 | Professional Automotive Product Classic | Automotive | $623.44 | 314 | ★ 1.5 | 432 | SKU-001893 |
| 1894 | Super Office Supplies Product Advanced | Office Supplies | $307.11 | 325 | ★ 1.6 | 0 | SKU-001894 |
| 1895 | Deluxe Toys & Games Product Special Edition | Toys & Games | $505.15 | 451 | ★ 1.3 | 617 | SKU-001895 |
| 1897 | Super Health & Beauty Product Mini | Health & Beauty | $467.78 | 55 | ★ 3.1 | 123 | SKU-001897 |
| 1898 | Standard Office Supplies Product Classic | Office Supplies | $507.10 | 26 | ★ 3.8 | 700 | SKU-001898 |
| 1899 | Elite Sports & Outdoors Product Lite | Sports & Outdoors | $701.19 | 412 | ★ 2.5 | 255 | SKU-001899 |
| 1900 | Super Automotive Product Special Edition | Automotive | $47.84 | 178 | ★ 1.7 | 67 | SKU-001900 |
| 1901 | Ultra Sports & Outdoors Product 2024 | Sports & Outdoors | $525.42 | 481 | ★ 2.6 | 168 | SKU-001901 |
| 1904 | Premium Health & Beauty Product Plus | Health & Beauty | $171.85 | 27 | ★ 1.0 | 504 | SKU-001904 |
| 1905 | Premium Electronics Product Special Edition | Electronics | $523.36 | 126 | ★ 1.5 | 303 | SKU-001905 |
| 1906 | Mega Office Supplies Product Advanced | Office Supplies | $142.71 | 285 | ★ 3.2 | 448 | SKU-001906 |
| 1907 | Ultra Health & Beauty Product Lite | Health & Beauty | $854.68 | 244 | ★ 3.4 | 415 | SKU-001907 |
| 1908 | Ultra Food & Grocery Product Max | Food & Grocery | $268.72 | 99 | ★ 2.3 | 86 | SKU-001908 |
| 1909 | Premium Automotive Product Mini | Automotive | $455.98 | 22 | ★ 3.0 | 334 | SKU-001909 |
| 1912 | Economy Clothing Product Advanced | Clothing | $981.45 | 129 | ★ 5.0 | 847 | SKU-001912 |
| 1913 | Elite Food & Grocery Product Pro | Food & Grocery | $696.96 | 147 | ★ 1.8 | 604 | SKU-001913 |
| 1914 | Ultra Electronics Product Special Edition | Electronics | $581.44 | 208 | ★ 2.9 | 243 | SKU-001914 |
| 1915 | Pro Food & Grocery Product Lite | Food & Grocery | $602.14 | 62 | ★ 1.2 | 696 | SKU-001915 |
| 1916 | Professional Electronics Product 2024 | Electronics | $437.76 | 405 | ★ 1.6 | 786 | SKU-001916 |
| 1917 | Super Sports & Outdoors Product Mini | Sports & Outdoors | $243.34 | 377 | ★ 4.4 | 854 | SKU-001917 |
| 1918 | Deluxe Toys & Games Product 2024 | Toys & Games | $613.90 | 288 | ★ 3.0 | 341 | SKU-001918 |
| 1919 | Standard Clothing Product 2024 | Clothing | $246.39 | 17 | ★ 4.0 | 959 | SKU-001919 |
| 1920 | Super Books Product Special Edition | Books | $420.49 | 479 | ★ 1.2 | 383 | SKU-001920 |
| 1922 | Super Electronics Product 2024 | Electronics | $418.32 | 483 | ★ 2.9 | 61 | SKU-001922 |
// 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
};
}