Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10335 | Bulk Product 1f5b41c9 | Books | $832.32 | 10 | ★ 1.1 | 8 | BULK-5d87d1c9 |
| 10336 | Bulk Product 219f1e3b | Home & Garden | $979.38 | 216 | ★ 2.2 | 29 | BULK-02d4975a |
| 10337 | Bulk Product de484c21 | Electronics | $652.65 | 139 | ★ 4.1 | 94 | BULK-8729f13f |
| 10338 | Bulk Product 149f5dcb | Electronics | $642.13 | 12 | ★ 3.1 | 69 | BULK-671726db |
| 10339 | Bulk Product d620a391 | Clothing | $294.55 | 462 | ★ 4.0 | 5 | BULK-652606d1 |
| 10340 | Bulk Product 79d8ba62 | Toys & Games | $871.27 | 91 | ★ 3.3 | 35 | BULK-3b65fd58 |
| 10341 | Bulk Product 104d9e97 | Electronics | $39.18 | 481 | ★ 0.2 | 30 | BULK-767d6c42 |
| 10342 | Bulk Product ca6b78cd | Sports & Outdoors | $944.55 | 363 | ★ 0.7 | 88 | BULK-a24b9f88 |
| 10343 | Bulk Product b2ebaf3b | Home & Garden | $836.53 | 67 | ★ 0.0 | 94 | BULK-eda7c288 |
| 10344 | Bulk Product 19cf0cad | Clothing | $453.79 | 352 | ★ 4.9 | 56 | BULK-aebbc708 |
| 10345 | Bulk Product e87c018b | Sports & Outdoors | $17.32 | 324 | ★ 2.3 | 27 | BULK-23767e60 |
| 10346 | Bulk Product 7cca0198 | Electronics | $559.79 | 338 | ★ 1.8 | 75 | BULK-2240f58c |
| 10347 | Bulk Product 8e700a2b | Books | $379.07 | 97 | ★ 3.7 | 79 | BULK-e7f4f0ec |
| 10348 | Bulk Product 3aa0835a | Home & Garden | $620.91 | 376 | ★ 3.3 | 25 | BULK-8164e209 |
| 10349 | Bulk Product 7a037301 | Home & Garden | $957.23 | 314 | ★ 4.7 | 7 | BULK-3f40b890 |
| 10350 | Bulk Product 266161c7 | Books | $509.79 | 468 | ★ 2.6 | 19 | BULK-c55a5a47 |
| 10351 | Bulk Product a6dba78b | Clothing | $252.60 | 107 | ★ 3.7 | 0 | BULK-6bea8b4b |
| 10352 | Bulk Product 2ede0562 | Sports & Outdoors | $944.21 | 456 | ★ 3.3 | 58 | BULK-dfd16da2 |
| 10353 | Bulk Product c89cfbc9 | Electronics | $253.56 | 301 | ★ 2.7 | 52 | BULK-6d797271 |
| 10354 | Bulk Product ac76ca11 | Home & Garden | $728.81 | 348 | ★ 1.5 | 50 | BULK-a18cd51c |
| 10355 | Bulk Product 9ea6da42 | Home & Garden | $172.54 | 242 | ★ 3.2 | 76 | BULK-224ab9b3 |
| 10356 | Bulk Product 784f1345 | Toys & Games | $953.30 | 327 | ★ 3.1 | 36 | BULK-7e082e9f |
| 10357 | Bulk Product 7a542e47 | Clothing | $140.20 | 366 | ★ 4.4 | 84 | BULK-a2be34c6 |
| 10358 | Bulk Product ac566758 | Sports & Outdoors | $57.11 | 60 | ★ 1.6 | 36 | BULK-eeb1c15c |
| 10359 | Bulk Product 9fc4346f | Sports & Outdoors | $243.48 | 201 | ★ 3.8 | 59 | BULK-884d9165 |
// 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
};
}