Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

566 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 566 Results Showing 14126 - 14150 of 24441

ID Name Category Price Stock Rating Reviews SKU
14685 Bulk Product 36f8658a Electronics $327.19 394 1.7 48 BULK-0283a716
14686 Bulk Product 2828ffce Electronics $524.28 37 0.4 3 BULK-2c75f0c6
14687 Bulk Product e2b790c0 Sports & Outdoors $490.06 334 3.4 70 BULK-5adf2f9a
14688 Bulk Product 6013f2c1 Toys & Games $822.60 138 4.2 11 BULK-be956c8d
14689 Bulk Product e066e78b Toys & Games $736.05 42 1.2 9 BULK-3e534c7e
14690 Bulk Product 0157ad19 Clothing $624.21 189 0.6 66 BULK-85f9f0dc
14691 Bulk Product e5680b33 Home & Garden $1,007.62 410 3.5 64 BULK-bd53c458
14692 Bulk Product d376504b Clothing $885.85 357 3.6 70 BULK-90230d2e
14693 Bulk Product 304e682e Toys & Games $609.67 483 3.6 4 BULK-9d2fe928
14694 Bulk Product 1feaa5ab Sports & Outdoors $26.52 437 4.8 21 BULK-dd503dc9
14695 Bulk Product e37602eb Toys & Games $455.79 88 4.3 78 BULK-8b39a148
14696 Bulk Product 63b8f6c1 Books $975.33 178 1.2 84 BULK-10ea48f5
14697 Bulk Product a25c93bf Books $35.90 117 3.7 78 BULK-c06d97b4
14698 Bulk Product 4054d03a Toys & Games $878.42 430 4.2 30 BULK-21e9bf81
14699 Bulk Product 1c62197b Sports & Outdoors $307.92 90 4.3 7 BULK-9dcfcdd6
14700 Bulk Product d6c802b3 Electronics $427.16 493 0.6 42 BULK-bb8d825d
14701 Bulk Product 27c567f5 Clothing $59.61 381 3.2 46 BULK-f4027973
14702 Bulk Product 980d2e5a Toys & Games $84.81 233 0.5 20 BULK-3b11c27e
14703 Bulk Product 902582d3 Sports & Outdoors $162.26 117 1.5 23 BULK-bd4f17fe
14704 Bulk Product 594020dd Home & Garden $161.45 290 0.7 24 BULK-7ebcd845
14705 Bulk Product 40c73bb6 Home & Garden $34.73 263 0.7 87 BULK-158766c6
14706 Bulk Product 229741bc Toys & Games $326.61 169 1.5 51 BULK-03c42e96
14707 Bulk Product 913d9d12 Home & Garden $679.34 128 2.3 13 BULK-d631c741
14708 Bulk Product 8a5b8dd8 Sports & Outdoors $577.13 271 4.5 59 BULK-ac92317e
14709 Bulk Product 5b2480b4 Electronics $846.17 152 1.1 34 BULK-cb5dd6b5
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