Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

34 ms

Page Size

25

Current Page

932 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 932 Results Showing 23276 - 23300 of 24441

ID Name Category Price Stock Rating Reviews SKU
23835 Bulk Product 333ed02c Sports & Outdoors $699.72 232 0.0 23 BULK-e757dbd2
23836 Bulk Product 97e73f2a Clothing $487.35 44 0.8 77 BULK-32a1d99d
23837 Bulk Product 033ea2af Clothing $315.06 147 3.6 99 BULK-d312dab2
23838 Bulk Product f1042bb2 Sports & Outdoors $127.51 134 4.6 73 BULK-31c9bb15
23839 Bulk Product e7bb633a Books $295.95 475 4.2 69 BULK-0d11c0b8
23840 Bulk Product 369a6b52 Books $468.47 388 5.0 97 BULK-a81cc4ae
23841 Bulk Product 4f382d50 Sports & Outdoors $156.54 479 2.1 52 BULK-7dae706e
23842 Bulk Product 54337eb6 Electronics $721.93 141 4.6 14 BULK-89810dc5
23843 Bulk Product 7f2a2ae9 Sports & Outdoors $742.23 348 3.7 22 BULK-233a2586
23844 Bulk Product e461b8fb Electronics $397.35 314 3.2 88 BULK-414fa993
23845 Bulk Product fc05cde3 Clothing $274.27 373 0.1 46 BULK-ca8bda56
23846 Bulk Product 2b30e4af Home & Garden $930.13 419 0.6 27 BULK-6aa56935
23847 Bulk Product 172527ba Clothing $236.83 146 0.9 9 BULK-7d02111f
23848 Bulk Product 9e8701dc Electronics $904.75 478 0.9 73 BULK-c272f355
23849 Bulk Product 63e3a303 Electronics $360.86 0 1.3 17 BULK-68419bb4
23850 Bulk Product 9a0472de Electronics $1,006.11 347 3.2 62 BULK-466c4102
23851 Bulk Product c76ee052 Clothing $655.17 104 1.0 71 BULK-57a9cef3
23852 Bulk Product 616a329d Books $617.63 233 1.5 76 BULK-60656d43
23853 Bulk Product 4c1ea7df Electronics $757.64 327 0.9 34 BULK-8032a031
23854 Bulk Product b4a52797 Toys & Games $844.31 477 3.0 16 BULK-02a7e081
23855 Bulk Product 148ec0b2 Electronics $153.71 135 1.2 58 BULK-b0ded9ea
23856 Bulk Product 300e4ed3 Books $820.15 83 1.6 69 BULK-b016621e
23857 Bulk Product de5ce372 Clothing $139.78 9 3.0 95 BULK-94f5623e
23858 Bulk Product 6137f1c5 Home & Garden $393.55 336 1.1 23 BULK-618d5b56
23859 Bulk Product b9b3f338 Home & Garden $499.02 126 1.1 58 BULK-a10d6333
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