Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

43 ms

Page Size

25

Current Page

794 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 794 Results Showing 19826 - 19850 of 24441

ID Name Category Price Stock Rating Reviews SKU
20385 Bulk Product 48ae8141 Toys & Games $839.95 482 3.5 77 BULK-bb332684
20386 Bulk Product 066bb65a Electronics $354.51 154 0.1 86 BULK-3a65eb3e
20387 Bulk Product fcbb9976 Home & Garden $785.78 163 3.8 58 BULK-e57b6f4f
20388 Bulk Product d910b38c Toys & Games $56.04 184 4.8 79 BULK-466e56ae
20389 Bulk Product 597f0089 Electronics $311.38 101 0.9 48 BULK-f6232fe5
20390 Bulk Product 6ea73cca Electronics $561.97 320 0.7 16 BULK-5a430223
20391 Bulk Product 75133815 Electronics $729.60 161 0.8 35 BULK-4b7acd8d
20392 Bulk Product 41d4bac5 Sports & Outdoors $120.59 358 2.7 39 BULK-2a632262
20393 Bulk Product e2c1b124 Electronics $811.49 129 4.2 7 BULK-6f179920
20394 Bulk Product 5e5c21f4 Electronics $173.68 488 4.4 61 BULK-63c01194
20395 Bulk Product 5d655c6c Clothing $50.93 31 0.8 18 BULK-b35aa73b
20396 Bulk Product 43b0c459 Home & Garden $93.77 254 1.5 35 BULK-da874a93
20397 Bulk Product baad641d Sports & Outdoors $81.62 44 1.9 73 BULK-494c64e2
20398 Bulk Product 700d4902 Electronics $187.15 105 0.9 72 BULK-fa71ff24
20399 Bulk Product e964ed95 Toys & Games $720.91 250 2.0 68 BULK-510759c0
20400 Bulk Product 6ef5116d Home & Garden $260.66 498 3.4 73 BULK-b2d6f12b
20401 Bulk Product d4f6c19f Clothing $994.58 285 0.3 96 BULK-f4a6a108
20402 Bulk Product ae6e93b9 Toys & Games $79.17 121 4.5 29 BULK-7edeab5d
20403 Bulk Product 3f2dffec Clothing $365.94 108 1.1 73 BULK-c399d9a6
20404 Bulk Product 51316ae4 Electronics $682.74 46 3.2 32 BULK-70b76fbc
20405 Bulk Product 2f4a210d Home & Garden $793.02 122 1.9 59 BULK-5c5f13f9
20406 Bulk Product 80f3c355 Books $733.45 424 4.5 95 BULK-4e3eb1a1
20407 Bulk Product 2c4f9a8c Books $1,002.33 497 0.5 12 BULK-581d764c
20408 Bulk Product 6f7f4733 Home & Garden $256.88 230 2.1 60 BULK-495e1483
20409 Bulk Product 28dd84b6 Home & Garden $387.91 403 2.6 82 BULK-3d17edb5
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