Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

501 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 501 Results Showing 12501 - 12525 of 24441

ID Name Category Price Stock Rating Reviews SKU
13060 Bulk Product 62e99c92 Toys & Games $763.76 213 1.4 12 BULK-b4289e41
13061 Bulk Product 75bf74e8 Electronics $153.35 304 3.1 94 BULK-981c1c79
13062 Bulk Product 22d6d660 Books $364.54 100 3.8 74 BULK-2b41373b
13063 Bulk Product cbeda65c Books $443.64 79 0.1 93 BULK-5c5a2fe2
13064 Bulk Product 6f0d2156 Sports & Outdoors $952.71 479 3.8 88 BULK-5c1e9817
13065 Bulk Product 5828ae0a Toys & Games $401.97 490 1.8 3 BULK-bfdf9559
13066 Bulk Product bbe59fd8 Home & Garden $912.33 451 3.5 54 BULK-910f28ec
13067 Bulk Product 2744bda6 Electronics $367.63 60 3.3 98 BULK-6c09d1ef
13068 Bulk Product 48eb679c Toys & Games $882.40 167 4.8 93 BULK-59d68be9
13069 Bulk Product 352e7256 Sports & Outdoors $591.90 485 0.9 60 BULK-cc1675bd
13070 Bulk Product 5c75c8f7 Books $849.75 380 2.1 46 BULK-347a8364
13071 Bulk Product 65d53c14 Electronics $746.58 289 4.6 62 BULK-f956726c
13072 Bulk Product 83da833f Sports & Outdoors $687.07 309 0.7 51 BULK-caa6b379
13073 Bulk Product f2b8c444 Clothing $272.23 491 2.8 51 BULK-dd79639b
13074 Bulk Product bce4d534 Books $299.09 424 4.2 5 BULK-ce963e8d
13075 Bulk Product 9bfa47b9 Home & Garden $363.99 302 3.8 51 BULK-acd4372a
13076 Bulk Product 8069d585 Electronics $907.97 323 2.1 55 BULK-c2faf35d
13077 Bulk Product eaddf024 Books $389.59 494 3.4 29 BULK-6d45c7e9
13078 Bulk Product cf7bf3a7 Toys & Games $109.63 0 3.0 67 BULK-77971b18
13079 Bulk Product 74af96b7 Books $933.08 484 0.1 21 BULK-09bdb0f2
13080 Bulk Product b9267414 Toys & Games $715.95 384 4.8 30 BULK-3dc120b1
13081 Bulk Product b4bc41e1 Home & Garden $880.43 471 1.5 91 BULK-f8a6950f
13082 Bulk Product f008504b Toys & Games $734.75 158 3.2 88 BULK-2310eda7
13083 Bulk Product d5820e0d Sports & Outdoors $754.63 241 1.3 26 BULK-060ee2ce
13084 Bulk Product cd29862d Home & Garden $892.46 66 0.0 35 BULK-e6e27509
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