Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

15 ms

Page Size

25

Current Page

764 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 764 Results Showing 19076 - 19100 of 24441

ID Name Category Price Stock Rating Reviews SKU
19635 Bulk Product 98cad1af Sports & Outdoors $847.72 322 1.6 40 BULK-085b4dc1
19636 Bulk Product 913253c0 Toys & Games $298.54 139 3.7 21 BULK-8b7a2a67
19637 Bulk Product 2da9110d Toys & Games $289.87 276 3.9 77 BULK-c9103d0d
19638 Bulk Product aef30944 Electronics $949.31 32 0.4 33 BULK-18fc86dd
19639 Bulk Product 78bda910 Books $982.76 241 4.7 2 BULK-951b08a2
19640 Bulk Product b6e9a78d Electronics $705.51 144 0.0 75 BULK-37f7c4ec
19641 Bulk Product e678451b Home & Garden $119.00 200 2.2 4 BULK-93769230
19642 Bulk Product 66d50632 Clothing $143.75 259 0.7 93 BULK-2a40c977
19643 Bulk Product 0a1ac21b Sports & Outdoors $114.41 379 1.3 2 BULK-a4257f69
19644 Bulk Product e589a825 Electronics $595.11 35 1.0 84 BULK-1a4fc918
19645 Bulk Product b0fae76e Electronics $195.74 405 4.4 18 BULK-ef97a2bc
19646 Bulk Product 3d2e4413 Home & Garden $406.79 125 4.4 48 BULK-e9f3cc85
19647 Bulk Product 3c842548 Toys & Games $916.05 135 2.4 77 BULK-5258d4e5
19648 Bulk Product 948b3427 Toys & Games $701.48 54 4.8 44 BULK-b4192910
19649 Bulk Product d0c96f1a Toys & Games $681.16 216 4.9 86 BULK-ea491ce7
19650 Bulk Product 04d4a68c Electronics $425.25 422 3.5 14 BULK-d86bd9a2
19651 Bulk Product af55c0e8 Toys & Games $163.13 276 3.8 87 BULK-e6bd9dce
19652 Bulk Product 83c8abc6 Sports & Outdoors $234.15 198 3.8 68 BULK-007eb5a9
19653 Bulk Product 248af907 Home & Garden $358.92 439 3.0 92 BULK-4ae6ee86
19654 Bulk Product 1664aebb Toys & Games $28.45 131 4.9 72 BULK-8a637d4e
19655 Bulk Product 25b2781c Home & Garden $461.73 224 3.0 20 BULK-4da3bff3
19656 Bulk Product 433a8777 Books $498.59 341 4.9 47 BULK-1057c1c5
19657 Bulk Product 67d254ad Sports & Outdoors $1,008.48 331 2.3 93 BULK-051a9246
19658 Bulk Product e8f03384 Clothing $24.46 38 2.1 96 BULK-5a4767ad
19659 Bulk Product 4ce80976 Sports & Outdoors $324.69 280 0.8 27 BULK-ad541a52
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