Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

34 ms

Page Size

25

Current Page

882 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 882 Results Showing 22026 - 22050 of 24441

ID Name Category Price Stock Rating Reviews SKU
22585 Bulk Product 6ad3e7ea Home & Garden $585.11 66 1.4 23 BULK-573b9c4b
22586 Bulk Product 26e7d863 Home & Garden $751.10 175 0.1 85 BULK-67ec7290
22587 Bulk Product e4566af4 Electronics $630.65 78 4.5 38 BULK-1d117869
22588 Bulk Product 71c33cd3 Sports & Outdoors $795.25 0 3.4 31 BULK-bf7dc47c
22589 Bulk Product 0b4240bb Electronics $635.25 188 0.0 99 BULK-e24e99cf
22590 Bulk Product 41912047 Toys & Games $198.81 399 1.5 1 BULK-e8a9b85a
22591 Bulk Product d5559296 Home & Garden $141.94 396 1.6 41 BULK-701ee05d
22592 Bulk Product ba5b3891 Home & Garden $131.38 321 2.6 4 BULK-33e7dae6
22593 Bulk Product ca40f870 Books $641.59 131 3.2 54 BULK-6221e7e0
22594 Bulk Product b7e2d67f Electronics $352.24 338 3.3 54 BULK-9689449b
22595 Bulk Product 326aa636 Electronics $59.65 266 2.0 26 BULK-9a66cb7b
22596 Bulk Product 2bff67dc Home & Garden $844.48 260 2.3 91 BULK-a98172db
22597 Bulk Product 219ed01e Clothing $239.87 335 1.8 54 BULK-01e7c652
22598 Bulk Product fee8ace4 Books $645.35 50 2.5 79 BULK-a815aba5
22599 Bulk Product 6eaaacc0 Books $422.17 307 4.7 0 BULK-99e183ae
22600 Bulk Product 18547e85 Books $482.87 389 1.1 25 BULK-828581dc
22601 Bulk Product 742f30e4 Home & Garden $989.85 171 4.7 67 BULK-58e741aa
22602 Bulk Product 4f6cb9eb Home & Garden $681.78 98 4.2 46 BULK-f979dba4
22603 Bulk Product 437e1a13 Clothing $790.89 448 4.9 53 BULK-97801fe2
22604 Bulk Product cdb1ee0e Home & Garden $131.71 313 0.4 24 BULK-6428f5a9
22605 Bulk Product eacf7abe Books $129.94 190 0.5 6 BULK-9d602f7b
22606 Bulk Product 353a5fd1 Home & Garden $487.80 140 1.8 42 BULK-b98b9803
22607 Bulk Product 81655b85 Toys & Games $37.71 113 4.1 21 BULK-07aa2745
22608 Bulk Product c0c7508d Home & Garden $797.52 32 1.2 5 BULK-cc1a54ac
22609 Bulk Product 454d1a0f Books $140.07 334 1.7 79 BULK-2864a781
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