Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

20 ms

Page Size

25

Current Page

855 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 855 Results Showing 21351 - 21375 of 24441

ID Name Category Price Stock Rating Reviews SKU
21910 Bulk Product be76c595 Sports & Outdoors $827.71 270 2.8 56 BULK-3abbea8e
21911 Bulk Product 2efd8742 Clothing $388.26 370 2.6 88 BULK-59aadf89
21912 Bulk Product c45d984b Toys & Games $489.87 296 2.9 38 BULK-f1d73134
21913 Bulk Product bfaaf3ff Toys & Games $567.00 66 2.0 81 BULK-36564cfb
21914 Bulk Product 15332c43 Electronics $116.59 346 1.1 91 BULK-42556a02
21915 Bulk Product 66593730 Sports & Outdoors $930.99 338 2.6 25 BULK-ace3a94b
21916 Bulk Product e3fd5b46 Toys & Games $393.45 72 1.7 40 BULK-1ee353a7
21917 Bulk Product a5851116 Electronics $652.79 426 1.0 23 BULK-fa688dc2
21918 Bulk Product 471c1387 Sports & Outdoors $156.59 436 0.4 40 BULK-1d4034c1
21919 Bulk Product 8ad9039f Clothing $649.75 479 3.3 49 BULK-14c156ab
21920 Bulk Product 4af8c52d Toys & Games $249.55 176 3.3 27 BULK-73cb2f4f
21921 Bulk Product 3080894d Toys & Games $766.22 46 1.4 60 BULK-0c0c64d7
21922 Bulk Product 09159d3d Toys & Games $451.46 333 1.7 59 BULK-74c7c1d0
21923 Bulk Product e9e87229 Books $346.89 395 0.5 56 BULK-3b5169dd
21924 Bulk Product c7a3d77a Sports & Outdoors $380.31 404 1.4 79 BULK-5881d0d0
21925 Bulk Product 27ee31c2 Clothing $82.16 401 4.9 1 BULK-59cba654
21926 Bulk Product 076fa462 Electronics $939.08 51 2.1 8 BULK-fb6c5852
21927 Bulk Product 82e05901 Books $630.76 340 2.2 58 BULK-d7d7356f
21928 Bulk Product f7e9cabc Clothing $411.12 227 4.3 89 BULK-28cbca85
21929 Bulk Product 2ca24dc1 Home & Garden $378.68 247 3.0 46 BULK-acb65c9a
21930 Bulk Product ff4ac5aa Toys & Games $927.00 407 0.9 99 BULK-671ad74f
21931 Bulk Product 69e1e5e1 Home & Garden $653.44 401 1.8 64 BULK-bd17db69
21932 Bulk Product 6afb6612 Toys & Games $454.03 446 0.2 77 BULK-99c3136b
21933 Bulk Product 761de609 Sports & Outdoors $255.96 99 4.2 18 BULK-5f9bbf0b
21934 Bulk Product 9722224a Books $514.88 10 0.1 29 BULK-95f528e8
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