Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

25

Current Page

515 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 515 Results Showing 12851 - 12875 of 24441

ID Name Category Price Stock Rating Reviews SKU
13410 Bulk Product 6bbd8540 Home & Garden $305.46 239 3.2 3 BULK-d2be0b3b
13411 Bulk Product efe7efa4 Books $192.58 16 0.1 32 BULK-fba9de85
13412 Bulk Product c0b6c8eb Home & Garden $383.98 213 3.0 31 BULK-5d5549a7
13413 Bulk Product 91db5075 Electronics $94.09 440 2.1 72 BULK-19c91de3
13414 Bulk Product f7750f04 Clothing $293.89 301 3.8 21 BULK-b7563aae
13415 Bulk Product 45c737e8 Books $942.41 322 3.9 39 BULK-6399d3d4
13416 Bulk Product 494549d5 Clothing $867.43 67 2.6 68 BULK-19fe99bf
13417 Bulk Product 94931751 Electronics $440.60 438 4.3 5 BULK-f47d0e2d
13418 Bulk Product a754d84a Clothing $694.51 247 1.6 15 BULK-adb91817
13419 Bulk Product 18ae0a1d Sports & Outdoors $541.20 204 4.3 29 BULK-c82d8daf
13420 Bulk Product a5e9490e Clothing $782.48 367 4.4 91 BULK-b6398b8a
13421 Bulk Product f612e8b7 Toys & Games $146.04 227 4.8 42 BULK-7aea2c96
13422 Bulk Product c52c9d24 Toys & Games $677.84 244 2.0 93 BULK-ae6244b7
13423 Bulk Product ac8f00ee Clothing $329.54 449 4.0 38 BULK-1277a8ea
13424 Bulk Product 8d459b09 Clothing $691.14 34 2.9 39 BULK-0fed3565
13425 Bulk Product 94baeb9c Toys & Games $808.44 431 4.0 12 BULK-ee6b1579
13426 Bulk Product 6f219d4b Home & Garden $977.37 358 1.3 27 BULK-817aa1e9
13427 Bulk Product ba1ed3dc Books $651.84 125 0.9 76 BULK-e1745f73
13428 Bulk Product dacef201 Electronics $861.10 333 2.1 24 BULK-30803465
13429 Bulk Product fba31c61 Electronics $61.67 64 2.9 46 BULK-93939412
13430 Bulk Product e81e700d Electronics $239.38 225 4.8 57 BULK-54bee6fb
13431 Bulk Product 22aca884 Books $926.54 212 0.6 42 BULK-3acb5bc8
13432 Bulk Product dc6bde48 Sports & Outdoors $82.54 119 4.1 5 BULK-0fafbb0e
13433 Bulk Product 15a3f66e Toys & Games $893.92 114 1.4 24 BULK-6e2592df
13434 Bulk Product 1a0a4a41 Books $444.32 113 0.2 94 BULK-8721fef2
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