Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5135 | Bulk Product 057a5bd8 | Toys & Games | $484.17 | 390 | ★ 3.4 | 33 | BULK-58d5677b |
| 5136 | Bulk Product 19c72f8c | Clothing | $679.59 | 114 | ★ 3.5 | 43 | BULK-62539efc |
| 5137 | Bulk Product 1cab2e66 | Toys & Games | $1,007.98 | 167 | ★ 3.3 | 32 | BULK-ae4b1535 |
| 5138 | Bulk Product d588f9f1 | Sports & Outdoors | $297.83 | 493 | ★ 4.8 | 10 | BULK-3a304542 |
| 5139 | Bulk Product ea539eb5 | Sports & Outdoors | $845.06 | 50 | ★ 1.7 | 21 | BULK-55659b39 |
| 5140 | Bulk Product 9e82d362 | Toys & Games | $532.23 | 91 | ★ 0.2 | 86 | BULK-c720232d |
| 5141 | Bulk Product 54f8992e | Sports & Outdoors | $453.33 | 82 | ★ 4.7 | 31 | BULK-b7aa815e |
| 5142 | Bulk Product 5e7c45b1 | Home & Garden | $27.70 | 193 | ★ 4.7 | 14 | BULK-04933536 |
| 5143 | Bulk Product 773d36b7 | Toys & Games | $549.89 | 178 | ★ 0.7 | 16 | BULK-1c3252d7 |
| 5144 | Bulk Product e7a4f333 | Books | $341.32 | 297 | ★ 3.6 | 75 | BULK-074ebb40 |
| 5145 | Bulk Product 2028d063 | Electronics | $594.51 | 49 | ★ 1.0 | 12 | BULK-cf59f5aa |
| 5146 | Bulk Product 75c3a52e | Clothing | $381.73 | 379 | ★ 0.5 | 98 | BULK-ad5216bc |
| 5147 | Bulk Product c6d64914 | Home & Garden | $202.49 | 268 | ★ 1.9 | 70 | BULK-647f162c |
| 5148 | Bulk Product ecff3d8d | Books | $751.19 | 366 | ★ 2.9 | 71 | BULK-cc6a0188 |
| 5149 | Bulk Product 7dd79f9f | Toys & Games | $888.75 | 165 | ★ 4.2 | 98 | BULK-2441054d |
| 5150 | Bulk Product bb66492f | Clothing | $788.72 | 96 | ★ 0.9 | 55 | BULK-8dcf493a |
| 5151 | Bulk Product 1068bdcb | Toys & Games | $1,007.19 | 112 | ★ 1.1 | 85 | BULK-bcb897ae |
| 5152 | Bulk Product f7839fda | Electronics | $296.33 | 134 | ★ 2.0 | 27 | BULK-e0adc3fc |
| 5153 | Bulk Product 673c135e | Home & Garden | $85.30 | 245 | ★ 0.1 | 79 | BULK-f48c4e74 |
| 5154 | Bulk Product 99b0bb30 | Sports & Outdoors | $483.51 | 168 | ★ 0.5 | 31 | BULK-d85a2f5a |
| 5155 | Bulk Product ec27ff8d | Electronics | $897.73 | 352 | ★ 1.3 | 36 | BULK-6d065fc5 |
| 5156 | Bulk Product 3734eca1 | Toys & Games | $387.05 | 126 | ★ 4.9 | 9 | BULK-5a0f222b |
| 5157 | Bulk Product 5286e963 | Clothing | $628.25 | 327 | ★ 2.1 | 2 | BULK-214257db |
| 5158 | Bulk Product 164cd9b4 | Sports & Outdoors | $392.96 | 60 | ★ 5.0 | 60 | BULK-ef942b4a |
| 5159 | Bulk Product 09b9e86c | Electronics | $286.29 | 433 | ★ 3.3 | 45 | BULK-7f4ef970 |
// 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
};
}