Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

321 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 321 Results Showing 8001 - 8025 of 24441

ID Name Category Price Stock Rating Reviews SKU
8560 Bulk Product 4b89cf73 Clothing $391.20 175 2.3 25 BULK-1bec8fcb
8561 Bulk Product bd5b7cf2 Toys & Games $303.25 40 2.5 59 BULK-0507aadf
8562 Bulk Product 268167e4 Clothing $538.68 10 2.8 35 BULK-32989ecb
8563 Bulk Product 31c73b01 Electronics $416.16 16 2.6 10 BULK-50395944
8564 Bulk Product 34b3288b Sports & Outdoors $516.52 28 4.1 73 BULK-13b20f2b
8565 Bulk Product e8b84591 Clothing $319.82 69 2.2 4 BULK-66d70b4f
8566 Bulk Product e556d796 Toys & Games $695.74 350 0.9 28 BULK-5f1f8e67
8567 Bulk Product 631a8b61 Home & Garden $219.64 467 3.6 6 BULK-bea1e8eb
8568 Bulk Product 723e9eb7 Electronics $253.48 231 2.9 74 BULK-509c55c8
8569 Bulk Product 549b8039 Home & Garden $110.46 224 0.5 20 BULK-141aaf96
8570 Bulk Product ed0d6975 Books $867.98 322 0.6 8 BULK-6c97c4a9
8571 Bulk Product de3e5302 Books $550.81 37 4.6 69 BULK-682b855d
8572 Bulk Product a69464c4 Sports & Outdoors $400.81 268 1.5 97 BULK-afa8e7b1
8573 Bulk Product 29e72787 Books $924.32 59 1.3 85 BULK-2ff47ba7
8574 Bulk Product 4274e6c6 Electronics $855.87 198 0.7 12 BULK-a87c336e
8575 Bulk Product ba6c8f19 Toys & Games $860.05 198 3.7 9 BULK-d7d31679
8576 Bulk Product e95d222c Home & Garden $130.39 265 0.2 29 BULK-736a8dc6
8577 Bulk Product e23ffdca Sports & Outdoors $241.48 114 3.4 34 BULK-f58a0cc0
8578 Bulk Product 2243e866 Sports & Outdoors $107.65 113 2.8 14 BULK-7878052b
8579 Bulk Product 0d1c349b Electronics $614.67 371 1.7 13 BULK-000f734a
8580 Bulk Product 40c7d45f Toys & Games $937.29 151 1.4 48 BULK-452fa1bd
8581 Bulk Product 368ac37b Clothing $710.43 308 3.0 41 BULK-d401ee0c
8582 Bulk Product fa2dcde9 Clothing $256.35 387 4.0 99 BULK-4023cd85
8583 Bulk Product 2730a55a Home & Garden $215.14 221 2.1 93 BULK-6fbddea8
8584 Bulk Product cf46103c Clothing $277.91 87 1.6 78 BULK-8a072cfa
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