Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

34 ms

Page Size

25

Current Page

271 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 271 Results Showing 6751 - 6775 of 24441

ID Name Category Price Stock Rating Reviews SKU
7310 Bulk Product 401d2a0c Sports & Outdoors $58.31 289 3.8 90 BULK-6f76a9c6
7311 Bulk Product f09151e2 Electronics $345.27 120 0.8 39 BULK-a0de6ab9
7312 Bulk Product ad82e1be Sports & Outdoors $669.11 301 1.2 45 BULK-8b0faa20
7313 Bulk Product ab9af309 Sports & Outdoors $999.99 218 2.5 37 BULK-1d03d10d
7314 Bulk Product 3a06b03f Books $25.77 297 1.3 4 BULK-af5b611a
7315 Bulk Product d219c72f Clothing $531.43 37 4.5 30 BULK-d6baefdb
7316 Bulk Product 7fb775d2 Toys & Games $384.87 175 1.3 85 BULK-0542cd45
7317 Bulk Product 94e733b0 Electronics $813.16 414 2.6 34 BULK-594c85b3
7318 Bulk Product 1f90687b Books $577.46 476 0.9 17 BULK-646228d3
7319 Bulk Product eb5f60d8 Sports & Outdoors $499.06 367 3.5 20 BULK-92ab2baa
7320 Bulk Product 9062c590 Toys & Games $33.87 476 0.7 80 BULK-0c6c332d
7321 Bulk Product 71a398c9 Electronics $313.48 115 1.3 23 BULK-7ff3979b
7322 Bulk Product b8a256b9 Books $169.76 323 3.3 90 BULK-b7efb528
7323 Bulk Product e6fc538b Clothing $338.01 214 0.5 1 BULK-f41d19a1
7324 Bulk Product b30752c4 Toys & Games $440.33 111 3.7 69 BULK-4be8f369
7325 Bulk Product 084987cf Electronics $214.88 489 1.2 26 BULK-b3cb6a1c
7326 Bulk Product 37fc8d25 Electronics $525.86 254 1.8 36 BULK-a7d28aaa
7327 Bulk Product d49f8d39 Electronics $470.94 360 5.0 63 BULK-e20188c9
7328 Bulk Product 725c5c71 Toys & Games $637.33 60 2.5 86 BULK-625f5754
7329 Bulk Product 0eb76560 Electronics $892.48 365 4.7 32 BULK-a3ee15bd
7330 Bulk Product 0683af3e Sports & Outdoors $100.30 241 3.5 61 BULK-31292003
7331 Bulk Product c2558055 Home & Garden $992.42 86 4.5 8 BULK-bab0f426
7332 Bulk Product 348d8027 Books $893.10 76 2.2 39 BULK-263b52ee
7333 Bulk Product 157d387a Books $350.82 226 1.5 6 BULK-e2158f2e
7334 Bulk Product 236bb10a Clothing $174.40 107 0.5 42 BULK-8b77c572
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