Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

632 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 632 Results Showing 15776 - 15800 of 24441

ID Name Category Price Stock Rating Reviews SKU
16335 Bulk Product 71353155 Books $245.41 453 4.6 23 BULK-eaf88ad7
16336 Bulk Product 097f46a5 Electronics $904.65 413 1.1 35 BULK-22eedd96
16337 Bulk Product a0167f8b Books $866.05 281 4.5 7 BULK-8522ed01
16338 Bulk Product 4f0c5a4c Home & Garden $648.46 154 3.3 27 BULK-92ad219c
16339 Bulk Product ca5d467a Clothing $442.96 353 2.5 16 BULK-70d4b581
16340 Bulk Product 865c40c2 Sports & Outdoors $385.42 454 2.1 47 BULK-f89ef0a7
16341 Bulk Product 277e089d Books $728.59 202 3.7 60 BULK-55972a06
16342 Bulk Product 1adbbae5 Sports & Outdoors $772.42 437 2.0 22 BULK-4963f1cd
16343 Bulk Product c4188c81 Sports & Outdoors $812.59 322 2.7 47 BULK-668393a6
16344 Bulk Product 33eefd3d Sports & Outdoors $993.79 108 1.6 19 BULK-d1b2aa73
16345 Bulk Product d25d7f15 Home & Garden $245.19 10 1.5 18 BULK-f0254538
16346 Bulk Product a1c4d007 Books $432.23 432 2.4 11 BULK-d6724feb
16347 Bulk Product 4842b136 Clothing $990.09 92 0.7 9 BULK-41567412
16348 Bulk Product 48e287aa Sports & Outdoors $930.90 30 4.2 38 BULK-0c00ce0c
16349 Bulk Product d9a9d5a0 Electronics $260.51 361 2.4 94 BULK-cd3c79b6
16350 Bulk Product 74ad12f9 Electronics $26.95 1 3.1 65 BULK-11637bc7
16351 Bulk Product 45427eea Clothing $252.04 440 1.4 46 BULK-ff020073
16352 Bulk Product 9075a438 Toys & Games $439.39 310 4.8 12 BULK-0c63de25
16353 Bulk Product 040de253 Books $263.15 254 3.7 66 BULK-0097529b
16354 Bulk Product 402fe13a Toys & Games $665.71 379 0.1 43 BULK-ab3b00d9
16355 Bulk Product 4cb87bb0 Sports & Outdoors $577.24 89 1.8 48 BULK-e7bc89a9
16356 Bulk Product a13330e8 Home & Garden $500.27 47 2.9 58 BULK-909cd268
16357 Bulk Product 265a5a6d Books $381.74 197 1.5 73 BULK-52dea818
16358 Bulk Product 097baa6b Toys & Games $960.92 487 3.0 15 BULK-1c223829
16359 Bulk Product ebff6d92 Home & Garden $391.18 267 3.7 70 BULK-1e84e346
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