Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

26 ms

Page Size

25

Current Page

682 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 682 Results Showing 17026 - 17050 of 24441

ID Name Category Price Stock Rating Reviews SKU
17585 Bulk Product f9eddf9e Electronics $506.72 174 1.2 20 BULK-2cf819d8
17586 Bulk Product f9340264 Sports & Outdoors $803.68 486 2.1 82 BULK-e569fc5c
17587 Bulk Product 3817ef9b Sports & Outdoors $232.79 207 3.9 64 BULK-29ea3ec5
17588 Bulk Product 4b9b5a8d Home & Garden $396.06 213 2.6 25 BULK-d003ea61
17589 Bulk Product 2972081e Clothing $239.52 481 2.4 26 BULK-7ab2fc07
17590 Bulk Product 06325cd1 Clothing $620.35 475 1.4 44 BULK-46cbb968
17591 Bulk Product 50c837e6 Electronics $228.48 115 4.5 85 BULK-76fcf34d
17592 Bulk Product a5848cf7 Clothing $84.67 316 3.1 7 BULK-ef92a106
17593 Bulk Product b7276cd4 Sports & Outdoors $885.95 356 0.1 13 BULK-42d66e73
17594 Bulk Product 67bab908 Sports & Outdoors $78.55 316 0.1 16 BULK-a70ca7d8
17595 Bulk Product 1f308b60 Clothing $731.92 92 2.5 43 BULK-75d1e7c0
17596 Bulk Product f0ce9a53 Electronics $64.61 430 2.5 98 BULK-7df1e2b9
17597 Bulk Product 3a46844b Electronics $851.71 6 2.5 92 BULK-2a1b69a6
17598 Bulk Product 13ec7338 Clothing $709.86 22 1.2 22 BULK-6d66461b
17599 Bulk Product e6831e7f Home & Garden $757.36 153 4.2 91 BULK-582390ae
17600 Bulk Product 9099d96a Books $327.74 30 0.5 7 BULK-73a3f822
17601 Bulk Product d2f8685d Sports & Outdoors $434.84 315 4.4 45 BULK-956450de
17602 Bulk Product 80d1a443 Electronics $930.19 420 3.8 4 BULK-f5d9c238
17603 Bulk Product bdfe006e Books $24.17 457 3.6 81 BULK-07226e83
17604 Bulk Product 478c5a19 Clothing $34.20 175 2.9 66 BULK-3bff4fbb
17605 Bulk Product 99bd199c Home & Garden $550.16 305 3.6 66 BULK-0a3ee932
17606 Bulk Product 430a56a7 Clothing $312.53 187 0.1 65 BULK-9e4a62f1
17607 Bulk Product b775199f Home & Garden $63.42 245 2.1 67 BULK-104ab582
17608 Bulk Product 265e7051 Books $260.70 275 0.5 85 BULK-5b1f24ed
17609 Bulk Product 18f6b4aa Home & Garden $511.87 48 3.5 16 BULK-99aa67f3
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