Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

561 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 561 Results Showing 14001 - 14025 of 24441

ID Name Category Price Stock Rating Reviews SKU
14560 Bulk Product 789f26b4 Home & Garden $655.27 131 4.4 26 BULK-ffb35643
14561 Bulk Product 52bfb439 Toys & Games $948.39 306 2.2 40 BULK-c936353f
14562 Bulk Product 47ad767f Books $55.60 273 4.0 29 BULK-7f79c043
14563 Bulk Product b84be087 Home & Garden $879.07 281 0.1 4 BULK-405fc767
14564 Bulk Product e75a8fb7 Sports & Outdoors $168.46 316 2.5 82 BULK-8eaafe65
14565 Bulk Product 3f7f355b Toys & Games $925.60 314 0.1 18 BULK-8b646027
14566 Bulk Product 3b76a7d7 Books $855.12 92 3.1 40 BULK-769def03
14567 Bulk Product 1e2de46c Books $154.66 373 1.9 84 BULK-961ce4b5
14568 Bulk Product 5374a4a6 Toys & Games $888.67 393 1.0 53 BULK-283028d8
14569 Bulk Product 4272fbb0 Sports & Outdoors $611.25 428 1.1 40 BULK-811448c8
14570 Bulk Product a131a715 Sports & Outdoors $660.13 443 3.4 71 BULK-1564a4a1
14571 Bulk Product 7d23d454 Clothing $872.26 233 1.2 20 BULK-f0cd351a
14572 Bulk Product 7cf1e02d Books $401.51 387 2.9 75 BULK-cb3e1c25
14573 Bulk Product 4b8e6633 Books $111.15 104 0.2 41 BULK-8798966c
14574 Bulk Product f01f0b13 Books $307.02 416 1.2 16 BULK-19c5c34e
14575 Bulk Product 31eec2be Clothing $202.96 106 3.4 17 BULK-7ba06491
14576 Bulk Product e787cd01 Clothing $55.31 221 0.6 18 BULK-16b89ecc
14577 Bulk Product 32456307 Clothing $95.92 261 1.6 71 BULK-90f356a1
14578 Bulk Product ca38b703 Toys & Games $637.75 135 1.5 18 BULK-09cccced
14579 Bulk Product d27ace4a Books $123.41 325 3.6 77 BULK-c7cd989d
14580 Bulk Product e6245f61 Electronics $600.59 454 0.2 70 BULK-5c217f10
14581 Bulk Product a4e2109b Clothing $376.37 210 0.4 83 BULK-aa4a444b
14582 Bulk Product 28c77948 Home & Garden $414.57 269 4.6 2 BULK-c790565a
14583 Bulk Product da7d35ad Home & Garden $549.21 309 1.3 8 BULK-ae046282
14584 Bulk Product 3c984bec Books $983.53 42 0.6 28 BULK-05a9a0e9
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