Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

918 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 918 Results Showing 22926 - 22950 of 24441

ID Name Category Price Stock Rating Reviews SKU
23485 Bulk Product 44008047 Sports & Outdoors $432.38 215 2.2 92 BULK-d9df93e0
23486 Bulk Product c32d9218 Toys & Games $916.42 395 3.0 40 BULK-2282cc87
23487 Bulk Product 9ac61e5f Sports & Outdoors $747.44 441 1.8 59 BULK-5b3315b2
23488 Bulk Product ecbb06ee Home & Garden $697.53 263 1.7 45 BULK-7398cee7
23489 Bulk Product 7ff37cf0 Electronics $920.08 475 4.8 13 BULK-9af29e48
23490 Bulk Product cb48c541 Home & Garden $454.85 127 2.5 71 BULK-bc8f26e4
23491 Bulk Product 7331b218 Clothing $367.76 371 4.1 28 BULK-19c7c3b1
23492 Bulk Product 76a48d00 Toys & Games $206.86 478 0.1 74 BULK-f49091a1
23493 Bulk Product 42dd51d5 Sports & Outdoors $62.61 454 1.3 11 BULK-fd8e1ae0
23494 Bulk Product 67066474 Home & Garden $733.54 168 3.8 38 BULK-4966204e
23495 Bulk Product b42ca005 Toys & Games $103.53 164 2.7 5 BULK-97be51bf
23496 Bulk Product 77652ca9 Home & Garden $717.16 157 4.1 7 BULK-aaa7dbc5
23497 Bulk Product 14bcea56 Electronics $144.54 205 2.1 54 BULK-0956af9f
23498 Bulk Product 9d8e9094 Electronics $169.58 223 0.7 75 BULK-9ba1f6fb
23499 Bulk Product feed60e6 Home & Garden $683.18 253 1.8 59 BULK-4c378cba
23500 Bulk Product 89521bc3 Sports & Outdoors $62.84 258 1.1 90 BULK-ec70c82f
23501 Bulk Product 7d269312 Home & Garden $957.00 147 4.6 33 BULK-705f6015
23502 Bulk Product dff116f6 Books $519.71 50 1.7 94 BULK-576335f9
23503 Bulk Product 09832c9f Clothing $507.97 423 0.2 89 BULK-b4efacd6
23504 Bulk Product 2136f09c Toys & Games $759.37 253 2.6 94 BULK-6c4333c0
23505 Bulk Product fb44eb50 Sports & Outdoors $82.56 128 1.3 27 BULK-72b06846
23506 Bulk Product a3290c75 Home & Garden $553.44 369 3.2 22 BULK-5be80d6b
23507 Bulk Product c6abb721 Electronics $341.46 276 2.7 81 BULK-3ca1065b
23508 Bulk Product 335fb46f Electronics $880.21 393 4.0 86 BULK-384132a0
23509 Bulk Product 58798071 Home & Garden $763.49 50 4.1 67 BULK-547bfc14
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