Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

12 ms

Page Size

25

Current Page

305 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 305 Results Showing 7601 - 7625 of 24441

ID Name Category Price Stock Rating Reviews SKU
8160 Bulk Product 192bdbcc Sports & Outdoors $899.89 208 4.4 49 BULK-b315f842
8161 Bulk Product 97e6b678 Sports & Outdoors $1,003.91 94 1.8 41 BULK-04f5f26a
8162 Bulk Product 89b08803 Sports & Outdoors $645.92 447 3.2 25 BULK-f2582f1c
8163 Bulk Product 9bbb31dd Clothing $1,003.75 374 0.5 12 BULK-0dd7f2e3
8164 Bulk Product e695de76 Toys & Games $185.64 469 1.0 57 BULK-65d4e216
8165 Bulk Product c1b36222 Sports & Outdoors $29.70 383 0.8 4 BULK-9d54d370
8166 Bulk Product 7051abc2 Books $60.58 436 1.9 3 BULK-064daf3f
8167 Bulk Product 99889e9b Home & Garden $678.99 209 2.1 74 BULK-1738a694
8168 Bulk Product b4874506 Electronics $234.41 129 3.0 46 BULK-6b1666a8
8169 Bulk Product e1abd34f Books $936.26 471 4.2 95 BULK-d67b7dd6
8170 Bulk Product 0433309c Sports & Outdoors $401.50 269 1.3 52 BULK-60983108
8171 Bulk Product 45ed614e Clothing $506.76 94 2.2 73 BULK-45fac731
8172 Bulk Product bd821867 Sports & Outdoors $111.27 46 3.6 56 BULK-9ed08454
8173 Bulk Product 2d4b5f59 Toys & Games $931.49 427 4.7 54 BULK-2aa6eee4
8174 Bulk Product 6b02e66f Home & Garden $638.77 486 2.8 99 BULK-a0a02146
8175 Bulk Product c5cf4eed Toys & Games $534.94 18 1.6 46 BULK-f4aa377b
8176 Bulk Product 96bf8b61 Clothing $675.32 40 4.3 53 BULK-449164bf
8177 Bulk Product 04297698 Books $205.21 446 4.8 25 BULK-0deddc0d
8178 Bulk Product 14ff637a Books $854.72 431 2.4 8 BULK-6cb273cd
8179 Bulk Product 8a8ac9aa Electronics $301.66 456 3.5 85 BULK-114fd1ea
8180 Bulk Product 9083a4cd Electronics $463.85 125 1.2 60 BULK-1c06a734
8181 Bulk Product 563743fa Sports & Outdoors $820.80 128 4.9 21 BULK-f750156a
8182 Bulk Product 27a9b600 Home & Garden $1,007.91 173 2.7 68 BULK-b4445064
8183 Bulk Product 90275e4a Books $242.29 142 4.0 62 BULK-cbdf5fc8
8184 Bulk Product de4ae29c Home & Garden $845.61 332 0.3 17 BULK-4d83a5be
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