Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

185 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 185 Results Showing 4601 - 4625 of 24441

ID Name Category Price Stock Rating Reviews SKU
5160 Bulk Product 726f7d7f Books $570.85 349 0.4 55 BULK-06f772a7
5161 Bulk Product 7028cc1d Home & Garden $660.14 163 1.7 14 BULK-c8f8b045
5162 Bulk Product 014564c5 Toys & Games $728.97 460 2.3 10 BULK-17df2f6c
5163 Bulk Product 38ba0d13 Toys & Games $899.06 330 2.8 25 BULK-93e2f758
5164 Bulk Product ba6e2b64 Books $51.02 42 1.9 72 BULK-dc4c3135
5165 Bulk Product b6e85dc6 Toys & Games $192.04 9 2.4 24 BULK-a45ee760
5166 Bulk Product 9368c9eb Books $676.14 382 2.0 89 BULK-3490cc01
5167 Bulk Product 5e753e06 Books $846.69 185 0.6 5 BULK-7339dd07
5168 Bulk Product c4bf4ea6 Toys & Games $467.13 486 4.0 65 BULK-1ef43859
5169 Bulk Product cc2a2bd1 Home & Garden $329.49 50 1.1 73 BULK-5b4caccf
5170 Bulk Product a7db2dd4 Home & Garden $482.11 7 1.2 52 BULK-bc7fea30
5171 Bulk Product a5b91ef4 Sports & Outdoors $819.34 268 3.1 9 BULK-74c006d7
5172 Bulk Product 034f4924 Sports & Outdoors $573.24 378 1.7 99 BULK-29bc363f
5173 Bulk Product 0ac4539c Toys & Games $127.41 28 4.9 50 BULK-38afaa56
5174 Bulk Product f6344b05 Clothing $915.87 126 4.8 92 BULK-82b03bf5
5175 Bulk Product eeb1bd19 Toys & Games $619.13 495 0.3 44 BULK-0401c69a
5176 Bulk Product f4eb439f Sports & Outdoors $763.76 270 3.8 91 BULK-10de36e7
5177 Bulk Product 098e365e Home & Garden $409.61 327 1.2 81 BULK-6b978933
5178 Bulk Product 7d332311 Toys & Games $487.08 291 4.9 24 BULK-9cc246af
5179 Bulk Product 116c5eaa Toys & Games $126.35 454 2.4 52 BULK-d77462ca
5180 Bulk Product 460a765e Home & Garden $435.11 413 1.2 38 BULK-7583844d
5181 Bulk Product 4e2d072d Electronics $303.43 317 5.0 27 BULK-20205a4f
5182 Bulk Product 33ab8022 Clothing $512.58 358 3.5 59 BULK-fb12f962
5183 Bulk Product 37218f42 Toys & Games $515.48 388 4.3 1 BULK-b9eb3ac2
5184 Bulk Product 5caebb57 Books $471.47 413 4.0 82 BULK-c9e12bb7
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