Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

731 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 731 Results Showing 18251 - 18275 of 24441

ID Name Category Price Stock Rating Reviews SKU
18810 Bulk Product 016f61a8 Toys & Games $66.37 252 4.5 5 BULK-02ba4cb0
18811 Bulk Product a6e6f0e9 Books $857.11 51 5.0 87 BULK-5cec24dd
18812 Bulk Product d28bd666 Toys & Games $921.57 384 3.5 99 BULK-bd46e55b
18813 Bulk Product ab394d37 Home & Garden $370.51 128 4.0 17 BULK-c39719d3
18814 Bulk Product 1bfa71f6 Toys & Games $906.49 224 4.4 59 BULK-630d913b
18815 Bulk Product 611f88a1 Toys & Games $583.25 233 0.0 70 BULK-2c334547
18816 Bulk Product f7385558 Clothing $175.62 214 1.8 54 BULK-a3ed9d0f
18817 Bulk Product 5733738d Sports & Outdoors $800.41 399 4.2 82 BULK-f7971624
18818 Bulk Product fa9ba5ef Home & Garden $964.97 208 0.6 39 BULK-a9361c6a
18819 Bulk Product b9cea0be Home & Garden $132.54 340 0.4 83 BULK-d0338790
18820 Bulk Product 28f09c96 Clothing $64.29 385 0.9 0 BULK-b8944ea4
18821 Bulk Product e860eba2 Sports & Outdoors $661.19 315 0.6 78 BULK-d2abb22b
18822 Bulk Product 6a32db37 Clothing $248.68 130 2.5 9 BULK-d6ba7e7a
18823 Bulk Product 5c42686a Electronics $167.66 347 4.7 29 BULK-aaddfcfc
18824 Bulk Product 1aba45f1 Electronics $819.38 69 2.2 0 BULK-e285f81d
18825 Bulk Product a84231fe Toys & Games $918.39 62 3.3 8 BULK-d08e6a44
18826 Bulk Product a6c0866c Clothing $231.38 324 2.2 60 BULK-314769cb
18827 Bulk Product fdd49b4b Books $174.25 405 2.5 53 BULK-f7582fcd
18828 Bulk Product 313f9fdc Books $859.18 103 0.5 2 BULK-0322fa09
18829 Bulk Product ed740178 Books $482.45 361 4.2 16 BULK-6e0115c3
18830 Bulk Product e3bdbce0 Home & Garden $493.72 107 0.6 62 BULK-1794bc69
18831 Bulk Product dcb69dd7 Sports & Outdoors $195.34 42 1.9 66 BULK-850c33c1
18832 Bulk Product e77401de Clothing $611.03 92 4.0 77 BULK-39924c4b
18833 Bulk Product d2fe9bb2 Toys & Games $843.00 298 0.7 82 BULK-1ddad3dc
18834 Bulk Product ab9d1a40 Books $639.13 434 3.6 19 BULK-8d7f7127
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