Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5510 | Bulk Product 628bab53 | Clothing | $417.34 | 470 | ★ 0.1 | 12 | BULK-d6389d4d |
| 5511 | Bulk Product 534597eb | Toys & Games | $603.15 | 317 | ★ 0.2 | 83 | BULK-4696040e |
| 5512 | Bulk Product e38ee727 | Toys & Games | $414.63 | 275 | ★ 2.4 | 38 | BULK-299feb77 |
| 5513 | Bulk Product fc081d14 | Electronics | $225.20 | 299 | ★ 3.5 | 40 | BULK-906edcd5 |
| 5514 | Bulk Product aa1e4e78 | Books | $891.01 | 139 | ★ 3.2 | 35 | BULK-f054f9e2 |
| 5515 | Bulk Product be546dbe | Clothing | $557.16 | 392 | ★ 0.0 | 11 | BULK-81f70ca5 |
| 5516 | Bulk Product ca6868f3 | Books | $36.11 | 315 | ★ 4.4 | 49 | BULK-341d0c82 |
| 5517 | Bulk Product 8ca36398 | Home & Garden | $337.79 | 330 | ★ 4.5 | 90 | BULK-70c598c6 |
| 5518 | Bulk Product 9867cb24 | Toys & Games | $122.62 | 205 | ★ 2.0 | 89 | BULK-e834596f |
| 5519 | Bulk Product 54366755 | Sports & Outdoors | $390.67 | 380 | ★ 2.7 | 95 | BULK-48ee836a |
| 5520 | Bulk Product 9b7a940b | Books | $998.22 | 233 | ★ 0.1 | 54 | BULK-838a215b |
| 5521 | Bulk Product 23887532 | Clothing | $734.20 | 210 | ★ 1.7 | 2 | BULK-791138f0 |
| 5522 | Bulk Product 6e7b2745 | Clothing | $1,000.20 | 31 | ★ 3.9 | 61 | BULK-f3eab933 |
| 5523 | Bulk Product 026dcd8f | Electronics | $760.21 | 35 | ★ 3.2 | 25 | BULK-91eee4d4 |
| 5524 | Bulk Product 90eac56d | Home & Garden | $940.27 | 6 | ★ 1.6 | 9 | BULK-173ebf74 |
| 5525 | Bulk Product 781a6324 | Toys & Games | $113.28 | 425 | ★ 0.0 | 1 | BULK-6f9354bf |
| 5526 | Bulk Product a6c0fa51 | Electronics | $470.38 | 480 | ★ 0.8 | 85 | BULK-d4c8e219 |
| 5527 | Bulk Product f74bd4f8 | Sports & Outdoors | $865.50 | 495 | ★ 0.0 | 83 | BULK-84c76d26 |
| 5528 | Bulk Product 1316bd4a | Books | $171.54 | 184 | ★ 3.7 | 26 | BULK-a83e3eec |
| 5529 | Bulk Product 1beceff9 | Sports & Outdoors | $864.39 | 364 | ★ 4.7 | 83 | BULK-c1fc0199 |
| 5530 | Bulk Product 9198e499 | Electronics | $878.36 | 309 | ★ 4.9 | 5 | BULK-d368e495 |
| 5531 | Bulk Product 9d756eab | Sports & Outdoors | $49.84 | 483 | ★ 5.0 | 72 | BULK-5d48df08 |
| 5532 | Bulk Product f47f0725 | Sports & Outdoors | $133.01 | 287 | ★ 3.4 | 94 | BULK-423d211b |
| 5533 | Bulk Product 38e78a22 | Sports & Outdoors | $127.68 | 176 | ★ 0.5 | 86 | BULK-bdf6eda7 |
| 5534 | Bulk Product ca7a76de | Toys & Games | $689.70 | 468 | ★ 3.9 | 5 | BULK-16411b1c |
| 5535 | Bulk Product 9267e58c | Clothing | $845.89 | 135 | ★ 2.6 | 47 | BULK-3518ed8f |
| 5536 | Bulk Product 3992ca26 | Home & Garden | $863.85 | 450 | ★ 4.4 | 84 | BULK-1f852dc8 |
| 5537 | Bulk Product 99c704f4 | Books | $803.46 | 259 | ★ 1.7 | 83 | BULK-262b4947 |
| 5538 | Bulk Product 0b0e650c | Toys & Games | $93.15 | 172 | ★ 0.3 | 89 | BULK-b247affb |
| 5539 | Bulk Product 189e5aee | Home & Garden | $427.44 | 447 | ★ 4.7 | 32 | BULK-68f9b043 |
| 5540 | Bulk Product 97fba9f6 | Toys & Games | $867.88 | 434 | ★ 3.4 | 25 | BULK-1ca2efff |
| 5541 | Bulk Product 66ea4784 | Books | $536.77 | 237 | ★ 5.0 | 77 | BULK-9aa7366d |
| 5542 | Bulk Product 836fcfaf | Sports & Outdoors | $81.47 | 114 | ★ 1.9 | 68 | BULK-677d8602 |
| 5543 | Bulk Product 23a8f36d | Clothing | $409.77 | 161 | ★ 3.8 | 30 | BULK-a470c630 |
| 5544 | Bulk Product 8134e7f6 | Toys & Games | $301.58 | 15 | ★ 1.9 | 96 | BULK-a83b59fd |
| 5545 | Bulk Product 9e9a8f34 | Toys & Games | $903.02 | 460 | ★ 1.0 | 85 | BULK-5e712a1c |
| 5546 | Bulk Product 9f90d1eb | Electronics | $889.63 | 496 | ★ 4.3 | 98 | BULK-dda33f06 |
| 5547 | Bulk Product 9fda4b0d | Sports & Outdoors | $44.76 | 147 | ★ 0.8 | 88 | BULK-ecd489a2 |
| 5548 | Bulk Product b6d32c3f | Clothing | $412.99 | 11 | ★ 4.8 | 98 | BULK-4f498b73 |
| 5549 | Bulk Product cb5b42ff | Books | $94.28 | 429 | ★ 2.8 | 23 | BULK-fa4c7ae7 |
| 5550 | Bulk Product 664b44a6 | Sports & Outdoors | $88.60 | 40 | ★ 0.5 | 59 | BULK-0262afd5 |
| 5551 | Bulk Product 21f84907 | Electronics | $50.05 | 402 | ★ 4.6 | 68 | BULK-c78bdd60 |
| 5552 | Bulk Product 2daa795b | Clothing | $679.13 | 36 | ★ 3.9 | 63 | BULK-1d7d7707 |
| 5553 | Bulk Product bcbe3181 | Sports & Outdoors | $124.08 | 228 | ★ 4.9 | 46 | BULK-5130aed5 |
| 5554 | Bulk Product 7a08c0b3 | Electronics | $104.16 | 274 | ★ 3.9 | 81 | BULK-ef06ad66 |
| 5555 | Bulk Product c24ecebd | Toys & Games | $771.12 | 336 | ★ 1.4 | 97 | BULK-7bf682d8 |
| 5556 | Bulk Product c622891d | Toys & Games | $729.35 | 293 | ★ 3.5 | 94 | BULK-a89776c0 |
| 5557 | Bulk Product 5877e02f | Electronics | $840.74 | 357 | ★ 0.5 | 14 | BULK-022faed2 |
| 5558 | Bulk Product a5d67d54 | Sports & Outdoors | $289.57 | 194 | ★ 2.5 | 53 | BULK-ef7accca |
| 5559 | Bulk Product e9022bcb | Clothing | $326.81 | 145 | ★ 2.1 | 87 | BULK-d31aae00 |
// 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
};
}