Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

23 ms

Page Size

25

Current Page

783 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 783 Results Showing 19551 - 19575 of 24441

ID Name Category Price Stock Rating Reviews SKU
20110 Bulk Product ad2d10c3 Home & Garden $953.47 122 2.6 7 BULK-ba411020
20111 Bulk Product 2dcc1e37 Books $353.43 84 2.7 64 BULK-0f9506cb
20112 Bulk Product 793ec087 Books $19.14 89 1.8 7 BULK-7f370f60
20113 Bulk Product 0d001126 Electronics $560.25 272 1.3 57 BULK-b73cdd46
20114 Bulk Product 7a47031a Books $989.00 51 1.8 21 BULK-7aa382b4
20115 Bulk Product b7ee4a8e Clothing $677.74 87 4.4 7 BULK-470aa7ea
20116 Bulk Product 022bc6ef Toys & Games $437.71 431 1.2 73 BULK-1e67d77b
20117 Bulk Product 64a3839d Sports & Outdoors $745.30 61 2.9 62 BULK-88517353
20118 Bulk Product f6ba489a Clothing $979.11 44 3.2 24 BULK-7a36d8fc
20119 Bulk Product cb50f972 Clothing $713.52 469 3.9 22 BULK-fbd563a1
20120 Bulk Product 2d805505 Toys & Games $669.13 442 0.7 72 BULK-595532f5
20121 Bulk Product 2dfd78a4 Home & Garden $93.71 414 4.1 76 BULK-aa35931e
20122 Bulk Product 70b89aed Books $183.35 115 2.5 18 BULK-5c1515ad
20123 Bulk Product 75976f0a Sports & Outdoors $675.30 8 4.2 68 BULK-346a44bc
20124 Bulk Product e3d19a99 Electronics $580.90 274 0.6 72 BULK-1bbc6767
20125 Bulk Product 8ea52a9c Home & Garden $219.49 387 3.4 33 BULK-00cebeb6
20126 Bulk Product 83c323a2 Sports & Outdoors $781.72 456 1.8 34 BULK-3d345cf3
20127 Bulk Product 726e382b Home & Garden $861.55 308 1.1 16 BULK-297f8910
20128 Bulk Product e4dd47b0 Clothing $247.76 388 2.6 22 BULK-5273cc14
20129 Bulk Product b63f491f Electronics $525.68 109 4.5 64 BULK-a3d01064
20130 Bulk Product 206dc0ab Clothing $473.18 396 4.3 97 BULK-4d9a0446
20131 Bulk Product 4ae10a95 Books $15.01 354 4.7 86 BULK-a0974ba6
20132 Bulk Product 71f98769 Toys & Games $999.78 309 4.5 80 BULK-410f837b
20133 Bulk Product fb18688d Home & Garden $938.63 112 0.0 19 BULK-c511cafb
20134 Bulk Product 1362c7d9 Electronics $721.17 401 2.1 18 BULK-e693ba1d
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