Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

106 ms

Page Size

25

Current Page

372 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 372 Results Showing 9276 - 9300 of 24441

ID Name Category Price Stock Rating Reviews SKU
9835 Bulk Product 85f59bb1 Electronics $52.24 442 2.5 61 BULK-7b58d18a
9836 Bulk Product b7135615 Sports & Outdoors $440.04 477 2.5 24 BULK-0b43872f
9837 Bulk Product 847b711e Toys & Games $449.56 352 3.7 69 BULK-217e263d
9838 Bulk Product b9fe8418 Home & Garden $968.18 214 3.2 78 BULK-1d6991d2
9839 Bulk Product f5f1d8bb Toys & Games $662.87 389 4.5 18 BULK-38be49b4
9840 Bulk Product 2a0a5ebe Clothing $221.42 474 4.8 67 BULK-6da7640e
9841 Bulk Product 0899007d Toys & Games $594.53 26 0.9 37 BULK-5be026b6
9842 Bulk Product 9dfa9f29 Sports & Outdoors $966.28 434 0.9 53 BULK-39504a16
9843 Bulk Product 3c9e8566 Electronics $813.83 491 2.2 43 BULK-ac273803
9844 Bulk Product 4d33740a Sports & Outdoors $719.29 279 3.6 31 BULK-7167d00d
9845 Bulk Product 17518e04 Toys & Games $439.51 172 0.9 36 BULK-03bf1f6e
9846 Bulk Product fa072ebf Home & Garden $325.12 93 4.6 7 BULK-7bbd0729
9847 Bulk Product 97c0524c Books $383.18 108 0.6 24 BULK-2ee624a7
9848 Bulk Product 9be14db0 Home & Garden $378.76 74 2.8 98 BULK-6472cc24
9849 Bulk Product 5d0fc8e0 Toys & Games $723.09 454 2.2 90 BULK-0574ad64
9850 Bulk Product 59ff8b4a Books $364.87 472 1.7 16 BULK-1eda80a5
9851 Bulk Product a6cd730f Books $776.17 55 0.1 62 BULK-c08a9256
9852 Bulk Product 190eac96 Electronics $231.71 278 4.8 48 BULK-8333ad16
9853 Bulk Product 26b15311 Home & Garden $732.08 470 2.6 18 BULK-67b84d40
9854 Bulk Product 22797dec Electronics $214.32 185 2.8 57 BULK-2258bec3
9855 Bulk Product 84f0b2c5 Toys & Games $474.78 73 1.9 95 BULK-bb5f5d12
9856 Bulk Product a30b84ee Toys & Games $440.87 185 2.9 98 BULK-171a044c
9857 Bulk Product 034e6301 Electronics $854.25 360 3.3 89 BULK-ad4f2d49
9858 Bulk Product 7d7c5598 Toys & Games $238.48 351 3.7 49 BULK-0cb55fba
9859 Bulk Product fb692ce9 Clothing $605.01 136 1.5 78 BULK-b961a97e
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