Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

13 ms

Page Size

25

Current Page

625 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 625 Results Showing 15601 - 15625 of 24441

ID Name Category Price Stock Rating Reviews SKU
16160 Bulk Product 5d7baeff Home & Garden $415.15 253 2.2 90 BULK-4abaad2d
16161 Bulk Product be288871 Electronics $777.09 87 2.3 22 BULK-24e7434d
16162 Bulk Product e6d534ba Electronics $117.13 131 1.0 39 BULK-a6af022c
16163 Bulk Product a0b02ee2 Books $461.67 238 1.0 84 BULK-dd6553d1
16164 Bulk Product bbf021a4 Clothing $1,003.49 408 1.4 53 BULK-74d46c6d
16165 Bulk Product af424950 Clothing $36.28 498 4.6 81 BULK-88c7f0e1
16166 Bulk Product 6705e436 Clothing $722.67 229 4.4 53 BULK-e6d76c1b
16167 Bulk Product 855ad151 Home & Garden $874.03 482 1.2 15 BULK-b32443ae
16168 Bulk Product 54b95fb4 Electronics $81.87 84 4.9 98 BULK-a39ff005
16169 Bulk Product 10740746 Home & Garden $618.27 255 4.8 86 BULK-3e67e0e6
16170 Bulk Product 30e87a20 Toys & Games $637.28 119 2.7 33 BULK-1c852f51
16171 Bulk Product 104b326c Toys & Games $377.26 109 1.7 99 BULK-0dd13ab3
16172 Bulk Product e84de23c Toys & Games $198.05 320 2.4 91 BULK-c1e9336a
16173 Bulk Product 3645c4ea Books $778.32 97 0.8 28 BULK-4ce667a7
16174 Bulk Product 61350be1 Home & Garden $248.16 130 4.6 59 BULK-ffee28d0
16175 Bulk Product 055ed5d0 Books $708.93 237 2.3 9 BULK-81f41729
16176 Bulk Product d0630462 Home & Garden $463.36 138 0.6 29 BULK-6f4c1874
16177 Bulk Product a9ddf62e Books $916.10 39 0.1 68 BULK-6e0bc259
16178 Bulk Product 9daba256 Toys & Games $461.85 434 1.4 66 BULK-a97b56d2
16179 Bulk Product af9b889f Home & Garden $145.54 417 2.3 5 BULK-0bd5db03
16180 Bulk Product dd26c6b9 Toys & Games $838.59 276 4.8 47 BULK-f6e9ecb1
16181 Bulk Product cfbe0ce6 Home & Garden $390.85 299 1.8 8 BULK-7b78beb2
16182 Bulk Product f4903140 Toys & Games $507.83 264 0.8 35 BULK-6297c41f
16183 Bulk Product d95aa044 Sports & Outdoors $940.81 135 4.6 8 BULK-80f5c331
16184 Bulk Product 4d1fe7cd Sports & Outdoors $444.53 274 4.0 19 BULK-77e05049
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