Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

30 ms

Page Size

25

Current Page

539 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 539 Results Showing 13451 - 13475 of 24441

ID Name Category Price Stock Rating Reviews SKU
14010 Bulk Product ac0b9a84 Sports & Outdoors $555.50 403 3.1 77 BULK-e2b6daa8
14011 Bulk Product ff9124c1 Home & Garden $189.76 231 1.7 78 BULK-09fef77b
14012 Bulk Product b1219df5 Electronics $139.57 60 3.1 17 BULK-9938e492
14013 Bulk Product c1e4b38e Books $496.80 319 4.0 39 BULK-94ad6458
14014 Bulk Product deea6454 Electronics $376.94 51 1.1 19 BULK-eabe08fc
14015 Bulk Product 4020996b Electronics $647.64 74 0.3 17 BULK-2650e273
14016 Bulk Product 4d1a8f3e Books $433.12 305 4.0 43 BULK-6162c43b
14017 Bulk Product c5cbc1c9 Clothing $948.91 111 2.3 28 BULK-07187964
14018 Bulk Product 67f8bd5a Clothing $175.59 100 1.3 61 BULK-7c1e948f
14019 Bulk Product 63200c2e Sports & Outdoors $561.66 460 3.8 83 BULK-ca40ad6a
14020 Bulk Product 573a843f Clothing $180.83 310 4.3 92 BULK-2acde905
14021 Bulk Product 44babd6e Toys & Games $76.93 183 4.8 26 BULK-97d0b239
14022 Bulk Product c8116823 Toys & Games $23.11 249 1.1 54 BULK-377e9f9f
14023 Bulk Product 9db39397 Sports & Outdoors $981.84 391 4.5 53 BULK-cdc85a3a
14024 Bulk Product 28c38435 Sports & Outdoors $20.38 187 4.5 22 BULK-25516019
14025 Bulk Product 020662bc Sports & Outdoors $460.03 452 2.0 62 BULK-fe15f3dc
14026 Bulk Product ccb4e583 Electronics $152.11 110 3.4 26 BULK-ca54c1fd
14027 Bulk Product 0d8574a8 Electronics $306.65 419 2.1 15 BULK-477885d4
14028 Bulk Product 49e59cae Electronics $176.97 317 1.2 21 BULK-6c011758
14029 Bulk Product a8744684 Toys & Games $486.04 377 4.9 48 BULK-2219770c
14030 Bulk Product 002f02cd Toys & Games $681.92 51 0.6 32 BULK-61c676d7
14031 Bulk Product 5e5ca87d Electronics $328.87 441 4.0 16 BULK-e1d5d19a
14032 Bulk Product c7989496 Clothing $475.45 464 1.3 29 BULK-de19871d
14033 Bulk Product 9f940abc Books $906.38 29 3.3 78 BULK-a4ad82fc
14034 Bulk Product 433cfec6 Electronics $875.80 166 2.0 38 BULK-f399021b
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