Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

963 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 963 Results Showing 24051 - 24075 of 24441

ID Name Category Price Stock Rating Reviews SKU
24610 Bulk Product fd027f52 Clothing $776.55 308 0.3 10 BULK-37e73053
24611 Bulk Product 593adbc1 Electronics $315.47 401 0.4 15 BULK-e1f48cab
24612 Bulk Product 3bbcfebb Sports & Outdoors $284.85 257 1.5 46 BULK-ba254278
24613 Bulk Product b84455aa Electronics $611.67 60 0.5 66 BULK-cf3b86c8
24614 Bulk Product b4ae60f6 Home & Garden $119.62 378 1.1 7 BULK-ec3695d0
24615 Bulk Product 39dddb2c Electronics $105.46 243 0.8 20 BULK-c4643215
24616 Bulk Product 426e5656 Toys & Games $490.97 447 4.7 94 BULK-56add5ef
24617 Bulk Product 63d23214 Books $183.97 348 1.0 99 BULK-9ebb18cd
24618 Bulk Product 8f7edf93 Clothing $400.36 364 0.6 3 BULK-09b08119
24619 Bulk Product ed2862d8 Sports & Outdoors $647.08 221 3.7 79 BULK-47a936e1
24620 Bulk Product d38f1336 Books $421.45 383 0.7 95 BULK-3a3283ba
24621 Bulk Product d95a3b11 Sports & Outdoors $632.37 163 3.0 76 BULK-337b77f8
24622 Bulk Product 4638d7cc Electronics $720.08 364 3.9 30 BULK-0b2d475c
24623 Bulk Product 8be9d977 Toys & Games $815.84 390 4.0 9 BULK-dfb17212
24624 Bulk Product 9f2d77b0 Home & Garden $398.05 401 3.6 2 BULK-9cd5666e
24625 Bulk Product 6921a264 Clothing $413.56 76 4.4 67 BULK-80bca9fa
24626 Bulk Product 13b03cef Sports & Outdoors $156.80 445 0.9 5 BULK-885c1ad5
24627 Bulk Product 88387b42 Clothing $420.58 61 1.1 89 BULK-d58b51a4
24628 Bulk Product b72a23df Electronics $262.09 183 2.4 38 BULK-e8972899
24629 Bulk Product e2dbe41a Electronics $779.93 328 3.7 77 BULK-e33a1bf7
24630 Bulk Product 4f2a07cd Electronics $429.66 468 2.9 49 BULK-7127cb4c
24631 Bulk Product 969b414d Sports & Outdoors $73.54 81 4.3 50 BULK-8bbcf1fe
24632 Bulk Product 4c5a3258 Toys & Games $152.47 359 1.8 43 BULK-b24bb5da
24633 Bulk Product 131c969d Clothing $679.73 45 0.1 11 BULK-ef8bdd53
24634 Bulk Product 11e7ce94 Toys & Games $932.93 64 2.4 46 BULK-aacede58
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