Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

576 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 576 Results Showing 14376 - 14400 of 24441

ID Name Category Price Stock Rating Reviews SKU
14935 Bulk Product 0036ded0 Books $349.96 273 2.3 27 BULK-4a2cfef2
14936 Bulk Product 15c3e854 Sports & Outdoors $487.70 207 3.0 73 BULK-38187485
14937 Bulk Product 8a007357 Clothing $267.10 187 2.7 81 BULK-5f9fb93c
14938 Bulk Product 574c6dda Toys & Games $427.16 152 4.1 72 BULK-1a277988
14939 Bulk Product f2a09cde Clothing $636.77 149 4.4 11 BULK-2fc54a34
14940 Bulk Product 4ac09f6a Books $534.82 111 1.6 46 BULK-c3041c82
14941 Bulk Product 2ee7d34c Books $515.60 330 1.7 23 BULK-c3e9a735
14942 Bulk Product dfcbe0a5 Home & Garden $211.04 444 4.2 98 BULK-a18539c6
14943 Bulk Product a6ea650c Electronics $663.98 335 1.8 85 BULK-e8a7387d
14944 Bulk Product 49ddcbdc Toys & Games $522.87 114 0.2 53 BULK-954b3217
14945 Bulk Product 939944ed Books $492.02 337 4.6 85 BULK-3152ff0c
14946 Bulk Product e06cdf29 Toys & Games $151.09 25 0.4 16 BULK-714bdcea
14947 Bulk Product fa64bda4 Sports & Outdoors $109.74 496 2.6 59 BULK-0c2f97a9
14948 Bulk Product 402ac5a6 Home & Garden $951.90 22 4.4 24 BULK-8aefad59
14949 Bulk Product 956bc32d Home & Garden $570.30 447 0.2 35 BULK-70e93d02
14950 Bulk Product ad0cbbe1 Toys & Games $810.97 225 0.7 45 BULK-38104115
14951 Bulk Product 2599f729 Books $702.62 2 3.1 16 BULK-5d8b3107
14952 Bulk Product ecb15452 Toys & Games $812.94 214 0.7 75 BULK-14924bea
14953 Bulk Product 82ebe1ff Clothing $707.17 487 2.1 89 BULK-b34c4da0
14954 Bulk Product e8e15de7 Toys & Games $902.42 40 3.6 81 BULK-cd90ce69
14955 Bulk Product 823e2b9a Books $742.91 107 3.8 89 BULK-58b38d5f
14956 Bulk Product 4aeef2a6 Books $390.45 239 0.9 61 BULK-c726368a
14957 Bulk Product ef0ffe99 Electronics $284.15 411 2.7 25 BULK-6e08eb6c
14958 Bulk Product cc0de580 Electronics $135.77 216 2.6 1 BULK-7d3be282
14959 Bulk Product 76d6a74c Clothing $960.02 299 1.6 90 BULK-e4960df1
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