Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

289 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 289 Results Showing 7201 - 7225 of 24441

ID Name Category Price Stock Rating Reviews SKU
7760 Bulk Product d96f8334 Clothing $330.81 235 2.7 84 BULK-ca8e8ea0
7761 Bulk Product 8540905b Sports & Outdoors $967.13 17 4.7 81 BULK-7e56d412
7762 Bulk Product 64154c20 Toys & Games $902.02 331 4.3 56 BULK-65597066
7763 Bulk Product da91ce23 Sports & Outdoors $288.32 469 2.5 80 BULK-236650fc
7764 Bulk Product 97cf971a Clothing $53.35 243 1.4 35 BULK-afe27464
7765 Bulk Product 365cb80b Sports & Outdoors $343.85 72 4.9 20 BULK-1eaeba3a
7766 Bulk Product aa905335 Clothing $273.30 387 0.5 84 BULK-04ac0e7b
7767 Bulk Product 4898ba49 Home & Garden $1,005.96 113 3.9 77 BULK-219ece6c
7768 Bulk Product 83b8386c Home & Garden $87.93 353 4.7 32 BULK-0f394eda
7769 Bulk Product 5cb60747 Books $478.48 255 0.6 54 BULK-0c45ce08
7770 Bulk Product 20cd54e9 Electronics $868.79 142 4.9 34 BULK-21da05de
7771 Bulk Product d39f5e8e Books $66.85 242 4.3 81 BULK-af770adb
7772 Bulk Product dd727889 Sports & Outdoors $808.01 93 1.0 86 BULK-aef2a1ca
7773 Bulk Product 7ee6cb1e Home & Garden $129.68 371 5.0 37 BULK-e0f58351
7774 Bulk Product b9f0eada Books $768.14 112 1.7 77 BULK-9436fcba
7775 Bulk Product 9d0726c7 Electronics $109.14 58 4.6 93 BULK-580253b8
7776 Bulk Product 917920b0 Sports & Outdoors $318.73 255 0.1 80 BULK-e92c83d6
7777 Bulk Product 3701cd70 Clothing $44.94 464 2.7 58 BULK-e2993a2f
7778 Bulk Product b1f7fee8 Sports & Outdoors $597.03 300 3.7 8 BULK-d0a31279
7779 Bulk Product 50f84377 Clothing $440.23 180 4.0 63 BULK-69dd26e5
7780 Bulk Product 6e682515 Books $848.16 324 4.9 10 BULK-d9e86efc
7781 Bulk Product 2896d18f Clothing $342.43 444 2.9 8 BULK-766cbc06
7782 Bulk Product e35d29d0 Toys & Games $77.68 352 3.5 87 BULK-b53f774d
7783 Bulk Product 39f8b619 Electronics $843.81 402 0.9 56 BULK-3de83f7c
7784 Bulk Product 34180eb0 Books $271.58 304 0.8 72 BULK-97133e85
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