Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

50

Current Page

480 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 480 Results Showing 23951 - 24000 of 24441

ID Name Category Price Stock Rating Reviews SKU
24510 Bulk Product 2ee663fc Sports & Outdoors $29.88 361 1.9 54 BULK-bed1e643
24511 Bulk Product 900bcefe Clothing $641.13 322 1.7 35 BULK-29429a3c
24512 Bulk Product d551888c Books $536.57 13 2.2 22 BULK-863862e5
24513 Bulk Product c98bfa6f Books $105.29 77 4.9 7 BULK-03880dfa
24514 Bulk Product d6f00030 Clothing $198.08 284 0.1 7 BULK-1d2e131f
24515 Bulk Product 3b931a14 Clothing $464.65 411 2.9 91 BULK-90960cab
24516 Bulk Product 02a2710b Toys & Games $50.41 52 1.1 32 BULK-7f0e5c1a
24517 Bulk Product a2412c8d Clothing $791.45 334 0.9 75 BULK-099ea747
24518 Bulk Product c753ce42 Electronics $897.37 325 1.9 84 BULK-7bbd363f
24519 Bulk Product 7a72cd49 Toys & Games $946.07 332 0.8 40 BULK-5cc30e87
24520 Bulk Product 54c24487 Books $530.96 219 0.5 89 BULK-5fb83355
24521 Bulk Product 85eb6bab Sports & Outdoors $378.65 238 2.3 42 BULK-7e472218
24522 Bulk Product d6f0d31f Electronics $27.18 27 0.7 24 BULK-97f90cf1
24523 Bulk Product 20424969 Toys & Games $766.90 49 4.1 22 BULK-40cda2c9
24524 Bulk Product 906a1cd9 Home & Garden $598.36 366 1.4 20 BULK-b11cb44a
24525 Bulk Product 48f00d2a Clothing $456.68 419 2.7 70 BULK-131be105
24526 Bulk Product f7437518 Home & Garden $442.46 17 1.8 49 BULK-0d17a0f8
24527 Bulk Product 0cbb4ff7 Clothing $228.91 29 2.2 78 BULK-ecd8e09b
24528 Bulk Product 99d8763a Books $941.41 29 4.2 4 BULK-716042d2
24529 Bulk Product 0eb305ca Toys & Games $345.53 338 2.1 94 BULK-cb2b96fe
24530 Bulk Product a94d85f8 Books $534.28 416 2.5 37 BULK-041534dd
24531 Bulk Product 188053d6 Home & Garden $695.81 329 1.1 32 BULK-4cb6331a
24532 Bulk Product 31cc3797 Sports & Outdoors $526.07 125 1.5 17 BULK-8acd6f41
24533 Bulk Product f3e780e1 Toys & Games $947.37 290 4.1 1 BULK-e668ee4b
24534 Bulk Product 3b878a3c Sports & Outdoors $860.69 78 1.5 35 BULK-48540615
24535 Bulk Product 70013059 Toys & Games $827.76 131 3.1 43 BULK-44eddb3c
24536 Bulk Product ed948a99 Home & Garden $39.14 299 4.4 96 BULK-736a9948
24537 Bulk Product 81850e2b Toys & Games $493.40 151 0.1 69 BULK-734ebfea
24538 Bulk Product 0526232e Home & Garden $328.21 373 3.7 92 BULK-51ce4958
24539 Bulk Product 664999c7 Electronics $314.63 18 2.4 68 BULK-05630431
24540 Bulk Product 9688d099 Electronics $342.52 394 4.6 83 BULK-7e43aa96
24541 Bulk Product 0219af47 Books $540.19 71 0.2 65 BULK-c036c826
24542 Bulk Product 06515dc2 Sports & Outdoors $841.69 74 0.3 89 BULK-8f80c77d
24543 Bulk Product 56e2c976 Sports & Outdoors $179.09 12 1.0 36 BULK-aa31f9ae
24544 Bulk Product b226d281 Books $271.07 295 4.0 47 BULK-28e196cb
24545 Bulk Product a9e3b3ec Books $963.70 50 4.6 88 BULK-3d4fd8c1
24546 Bulk Product 224698b9 Electronics $982.09 30 1.4 50 BULK-800b8a42
24547 Bulk Product 752c1b05 Home & Garden $106.48 369 4.6 48 BULK-3eb8cd9d
24548 Bulk Product 5d32c756 Toys & Games $947.52 30 4.8 78 BULK-e1f56041
24549 Bulk Product 3f542f9c Electronics $595.96 67 1.1 11 BULK-427fe164
24550 Bulk Product 92e36938 Sports & Outdoors $792.98 443 2.6 76 BULK-b7676538
24551 Bulk Product 9b6f927b Sports & Outdoors $396.58 282 3.9 72 BULK-e654ed37
24552 Bulk Product f87b8edd Books $219.87 381 4.8 94 BULK-7ed9a769
24553 Bulk Product 957f373a Clothing $957.49 425 2.6 70 BULK-c5fea4c7
24554 Bulk Product 1df4c514 Clothing $885.95 243 0.4 27 BULK-316f9bb5
24555 Bulk Product 0fa9d63e Sports & Outdoors $272.59 424 0.7 16 BULK-13a5f2ab
24556 Bulk Product b98623bf Home & Garden $510.86 61 4.5 57 BULK-aa6d002f
24557 Bulk Product 711439d4 Sports & Outdoors $903.79 362 4.3 51 BULK-ff6621f8
24558 Bulk Product a1e59be5 Clothing $611.41 184 2.2 38 BULK-93c7721d
24559 Bulk Product 10c30ea2 Toys & Games $375.95 433 2.0 48 BULK-8b7faf71
Implementation Code
// 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
    };
}
Pagination Best Practices
  • Always use OrderBy: Skip/Take require stable sorting for consistent results
  • Use AsNoTracking(): Pagination queries are typically read-only
  • Consider caching: Cache total count if dataset changes infrequently
  • Limit max page size: Prevent users from requesting too many records at once
  • Use indexed columns: Ensure ORDER BY columns are indexed for performance