Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

42 ms

Page Size

25

Current Page

802 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 802 Results Showing 20026 - 20050 of 24441

ID Name Category Price Stock Rating Reviews SKU
20585 Bulk Product e3e95bc3 Toys & Games $218.22 217 2.7 58 BULK-2ded9196
20586 Bulk Product 8c51e7ee Toys & Games $241.20 101 0.1 1 BULK-48725537
20587 Bulk Product c9e841e1 Sports & Outdoors $341.40 28 3.7 14 BULK-af229810
20588 Bulk Product 63cfc11c Sports & Outdoors $363.99 344 4.3 71 BULK-bd5acd11
20589 Bulk Product 06475de1 Sports & Outdoors $13.69 31 0.1 98 BULK-1031add3
20590 Bulk Product 474e66c8 Books $609.17 12 3.7 2 BULK-ef7c598e
20591 Bulk Product bd3ec1d4 Sports & Outdoors $461.96 144 2.0 88 BULK-86545ecc
20592 Bulk Product 321c8120 Clothing $963.84 435 3.7 89 BULK-439a5a7f
20593 Bulk Product 626fd571 Electronics $325.03 434 4.5 87 BULK-76ed57d5
20594 Bulk Product 6392cc79 Books $317.04 196 2.0 94 BULK-b99ad59e
20595 Bulk Product 5cb8b900 Electronics $810.52 162 1.2 17 BULK-d5949527
20596 Bulk Product 5795f06d Books $224.99 205 1.4 62 BULK-ee2fd1fa
20597 Bulk Product ea6c77f2 Home & Garden $345.24 212 1.6 20 BULK-165b56e2
20598 Bulk Product 0ca5d03c Sports & Outdoors $166.94 238 0.7 61 BULK-f151916f
20599 Bulk Product bdd6d031 Toys & Games $956.25 49 4.1 36 BULK-a822914c
20600 Bulk Product f9eba35a Books $586.26 182 0.1 57 BULK-d53af9c6
20601 Bulk Product d064a2de Home & Garden $245.84 496 1.1 96 BULK-7b579590
20602 Bulk Product 427202dc Home & Garden $338.91 342 4.1 1 BULK-a9865603
20603 Bulk Product 51626d77 Sports & Outdoors $839.15 79 0.5 31 BULK-b70b2a42
20604 Bulk Product 302b9ddc Sports & Outdoors $727.63 318 1.2 27 BULK-ecd69485
20605 Bulk Product 1bf62b22 Home & Garden $849.36 295 0.5 66 BULK-5d8512a0
20606 Bulk Product aa90bd18 Sports & Outdoors $709.98 143 0.8 18 BULK-890aa805
20607 Bulk Product 7dc796ad Home & Garden $211.48 166 1.7 32 BULK-0b4619b6
20608 Bulk Product 7f196b4f Books $633.71 326 0.0 91 BULK-c94aaedf
20609 Bulk Product 79d78cd2 Toys & Games $911.82 433 1.5 65 BULK-631bf3d3
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