Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

366 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 366 Results Showing 9126 - 9150 of 24441

ID Name Category Price Stock Rating Reviews SKU
9685 Bulk Product 6b3c73e1 Books $422.60 332 0.7 91 BULK-346ff453
9686 Bulk Product 468957cc Home & Garden $691.02 99 0.9 65 BULK-6b0e23ab
9687 Bulk Product 22442674 Clothing $752.87 271 2.3 3 BULK-9d55656d
9688 Bulk Product 7ef95401 Electronics $643.57 76 0.5 8 BULK-6b795668
9689 Bulk Product 0a75e332 Sports & Outdoors $507.78 165 1.0 20 BULK-c483cfca
9690 Bulk Product 65937373 Electronics $116.41 124 4.2 39 BULK-74a0874c
9691 Bulk Product c4196112 Home & Garden $618.97 132 4.5 47 BULK-9262786a
9692 Bulk Product 35ff580d Sports & Outdoors $144.76 301 0.1 44 BULK-47e7ce8c
9693 Bulk Product b148f8e2 Clothing $76.36 409 2.1 55 BULK-879fb4e8
9694 Bulk Product 171c29e2 Sports & Outdoors $504.66 284 4.9 37 BULK-690eaf1a
9695 Bulk Product 2822e969 Clothing $737.34 0 1.0 81 BULK-e5bef0c7
9696 Bulk Product 96b3ad62 Home & Garden $179.98 13 1.8 47 BULK-14b12ded
9697 Bulk Product 61dabf51 Home & Garden $419.47 485 2.4 4 BULK-b25978aa
9698 Bulk Product 2d63df3e Electronics $846.22 217 3.6 28 BULK-9d7feb32
9699 Bulk Product fc5a7802 Electronics $707.08 36 2.3 26 BULK-0ec6ba7c
9700 Bulk Product 8aa4f87f Toys & Games $32.58 154 0.3 72 BULK-5d1c547d
9701 Bulk Product 527fc001 Toys & Games $905.04 158 1.0 77 BULK-62d1a3a9
9702 Bulk Product b9ecd788 Toys & Games $729.03 306 3.4 46 BULK-08fde135
9703 Bulk Product 1456273d Books $666.85 104 3.5 49 BULK-8dbeb247
9704 Bulk Product d7495972 Sports & Outdoors $230.15 95 0.5 95 BULK-ec38b2e4
9705 Bulk Product 1f528e57 Toys & Games $981.06 29 1.8 17 BULK-37d952fd
9706 Bulk Product 18e91336 Sports & Outdoors $867.72 405 3.9 76 BULK-03aa0a0e
9707 Bulk Product 49c287df Clothing $494.38 205 3.2 91 BULK-8aa94483
9708 Bulk Product e1a149b0 Sports & Outdoors $897.13 403 0.8 17 BULK-e2d1dc24
9709 Bulk Product dcb0f9f7 Books $915.67 371 4.3 74 BULK-90c0faac
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