Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

383 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 383 Results Showing 9551 - 9575 of 24441

ID Name Category Price Stock Rating Reviews SKU
10110 Bulk Product 60aa0dae Books $378.43 48 0.0 4 BULK-4ad8a371
10111 Bulk Product 7534a1ad Sports & Outdoors $271.06 332 3.2 46 BULK-96b96fb0
10112 Bulk Product f50a3959 Clothing $31.65 317 1.0 14 BULK-5e744d4b
10113 Bulk Product 10bbc7b7 Sports & Outdoors $292.45 486 0.3 46 BULK-3745d740
10114 Bulk Product 3a38e085 Home & Garden $375.39 57 4.3 60 BULK-cb4b60cb
10115 Bulk Product 9d0ebb3d Home & Garden $791.18 59 3.1 99 BULK-a6d0f311
10116 Bulk Product ddb89625 Books $451.06 147 2.2 0 BULK-6a90e602
10117 Bulk Product baa734aa Books $117.35 259 1.1 85 BULK-0bd21f45
10118 Bulk Product defd7055 Toys & Games $342.73 318 3.5 3 BULK-798f59c7
10119 Bulk Product dd8dfa29 Electronics $184.79 200 0.8 24 BULK-a0433e38
10120 Bulk Product d8116b3c Books $644.12 281 1.9 43 BULK-9d841db7
10121 Bulk Product 9b19828c Books $868.86 321 3.6 20 BULK-0c08b70b
10122 Bulk Product ded0ce67 Toys & Games $174.63 485 0.2 47 BULK-fac21050
10123 Bulk Product 2aec0cd5 Books $761.73 111 0.5 53 BULK-4d9bc6df
10124 Bulk Product 4fd7484e Home & Garden $792.37 446 4.9 22 BULK-0b041bce
10125 Bulk Product 8dff8bd6 Toys & Games $218.37 8 3.2 71 BULK-284a7272
10126 Bulk Product 723831ff Toys & Games $600.18 474 4.6 38 BULK-9760d359
10127 Bulk Product faf4cb2b Clothing $175.64 303 3.0 90 BULK-128a64a1
10128 Bulk Product 6536d09e Electronics $377.63 264 2.0 26 BULK-17c69f76
10129 Bulk Product bf8a1967 Electronics $21.47 330 2.7 20 BULK-6d3183a0
10130 Bulk Product 83490c1e Books $98.71 382 3.9 82 BULK-ec9fc29d
10131 Bulk Product 8fb2b5af Electronics $731.17 129 4.5 26 BULK-f0fd3e7a
10132 Bulk Product ffa051d5 Sports & Outdoors $469.26 265 4.6 66 BULK-8d1c1551
10133 Bulk Product 64f52ed5 Electronics $562.79 134 1.1 56 BULK-5389916b
10134 Bulk Product 791ab2ae Electronics $596.51 318 0.8 99 BULK-1118c109
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