Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

14 ms

Page Size

25

Current Page

648 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 648 Results Showing 16176 - 16200 of 24441

ID Name Category Price Stock Rating Reviews SKU
16735 Bulk Product b5e05d2e Home & Garden $493.64 458 1.1 43 BULK-b456157f
16736 Bulk Product 0f4296ba Home & Garden $179.32 298 1.7 51 BULK-a198eb56
16737 Bulk Product 5e98b220 Sports & Outdoors $95.81 344 0.8 46 BULK-f96164a9
16738 Bulk Product b37d156d Books $945.56 280 3.1 72 BULK-bde5c6e2
16739 Bulk Product e05f7e16 Books $164.88 108 3.2 11 BULK-b6f37d0a
16740 Bulk Product 32c22933 Clothing $47.49 109 3.9 88 BULK-1fd31d8d
16741 Bulk Product d072e116 Sports & Outdoors $977.60 164 2.1 76 BULK-71b2210d
16742 Bulk Product ffe3ba1c Clothing $171.12 176 4.2 53 BULK-dc6b17f8
16743 Bulk Product 4de71f21 Clothing $102.64 109 3.1 61 BULK-4e948e0b
16744 Bulk Product 638bc38b Toys & Games $254.72 238 2.0 90 BULK-33ebf439
16745 Bulk Product f69c50ba Electronics $996.68 366 0.3 36 BULK-604d9ed4
16746 Bulk Product 92329279 Home & Garden $22.25 113 0.0 96 BULK-b59db224
16747 Bulk Product 88634070 Clothing $215.05 306 4.9 64 BULK-73552f1c
16748 Bulk Product 7905f28a Books $243.34 270 1.9 76 BULK-f4eca0af
16749 Bulk Product 4184ee89 Clothing $317.64 65 4.6 16 BULK-4001b792
16750 Bulk Product a0cd5823 Electronics $541.71 222 1.2 3 BULK-440c90e6
16751 Bulk Product 5dadddbe Toys & Games $467.61 399 2.9 61 BULK-442e731c
16752 Bulk Product aa0aea06 Home & Garden $410.32 202 1.9 70 BULK-c2f92fdb
16753 Bulk Product b3f70ce2 Electronics $612.74 125 0.3 35 BULK-575fcee1
16754 Bulk Product 8f92060e Books $387.81 252 3.1 50 BULK-126979ca
16755 Bulk Product 642686d4 Toys & Games $898.23 312 0.8 28 BULK-d5141815
16756 Bulk Product dbe3ce0b Sports & Outdoors $495.12 431 0.0 12 BULK-1395376d
16757 Bulk Product 4e739e0b Books $227.05 383 0.3 38 BULK-a8d568e2
16758 Bulk Product 02f3f904 Home & Garden $470.54 165 4.9 3 BULK-ddf40765
16759 Bulk Product 77738a57 Clothing $766.70 25 2.6 59 BULK-462dbd32
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