Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

482 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 482 Results Showing 12026 - 12050 of 24441

ID Name Category Price Stock Rating Reviews SKU
12585 Bulk Product 5419283f Clothing $985.15 321 3.2 8 BULK-dc8ec625
12586 Bulk Product c6e009e8 Home & Garden $846.25 161 4.0 91 BULK-d0d5ca69
12587 Bulk Product 682e51ae Electronics $736.83 212 3.1 81 BULK-2647832a
12588 Bulk Product 41740d9f Clothing $701.95 436 3.8 11 BULK-ca4a7046
12589 Bulk Product 67df0fdc Home & Garden $390.94 485 2.5 76 BULK-15b2e1be
12590 Bulk Product b640276e Books $332.64 382 4.0 39 BULK-e523733f
12591 Bulk Product 81c1b1ad Toys & Games $443.56 427 4.9 68 BULK-9c9e2e49
12592 Bulk Product 151ad4e4 Clothing $852.58 69 3.4 41 BULK-289d58d9
12593 Bulk Product cffd747a Books $14.55 87 4.3 65 BULK-551b1464
12594 Bulk Product f26f8eee Electronics $490.01 151 2.0 37 BULK-b279e5d0
12595 Bulk Product 9a57847e Electronics $434.22 73 1.4 55 BULK-7ea3e1e0
12596 Bulk Product b058004a Electronics $451.39 477 0.3 30 BULK-3e070b4f
12597 Bulk Product ba4122e8 Home & Garden $968.16 383 2.1 56 BULK-9f2fd2f3
12598 Bulk Product 616d3586 Home & Garden $854.04 406 2.8 63 BULK-2c09158f
12599 Bulk Product 01f759a9 Home & Garden $643.22 105 2.3 53 BULK-978032aa
12600 Bulk Product 8e9af764 Sports & Outdoors $613.38 236 4.5 43 BULK-c68354c9
12601 Bulk Product e7fa3635 Electronics $88.04 187 1.4 59 BULK-818b7767
12602 Bulk Product 9c3838d2 Electronics $248.62 297 3.9 3 BULK-81e8d130
12603 Bulk Product 897aa55f Clothing $288.47 90 1.9 73 BULK-8561674d
12604 Bulk Product b756f36e Home & Garden $749.20 430 3.3 25 BULK-2efc15e4
12605 Bulk Product 08f2a3e6 Sports & Outdoors $958.84 212 0.7 12 BULK-4f278cb7
12606 Bulk Product cbf7900d Clothing $583.91 185 0.9 73 BULK-97369f2c
12607 Bulk Product 479729df Clothing $913.74 10 3.8 73 BULK-4f2d98ef
12608 Bulk Product ce0f355f Sports & Outdoors $343.55 30 2.7 35 BULK-310f8a7d
12609 Bulk Product 79e73bd8 Sports & Outdoors $226.34 387 3.0 57 BULK-36aae316
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