Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

30 ms

Page Size

25

Current Page

705 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 705 Results Showing 17601 - 17625 of 24441

ID Name Category Price Stock Rating Reviews SKU
18160 Bulk Product eb7be421 Toys & Games $661.89 281 1.4 39 BULK-4e47a905
18161 Bulk Product 8d8f0fdb Electronics $538.81 196 2.6 10 BULK-9d6b041b
18162 Bulk Product 40a75e11 Electronics $519.71 477 3.0 18 BULK-59a9c21f
18163 Bulk Product cf493893 Sports & Outdoors $308.12 59 1.7 46 BULK-42e1f53b
18164 Bulk Product 47060e1f Toys & Games $545.51 221 0.4 5 BULK-d1d8f1d8
18165 Bulk Product ec6cfec5 Books $702.73 17 2.0 66 BULK-9414968f
18166 Bulk Product df2e8570 Sports & Outdoors $65.49 244 2.2 65 BULK-91e46b33
18167 Bulk Product 3f282fdc Electronics $280.94 267 0.4 22 BULK-06dd7ef0
18168 Bulk Product 95a4d292 Toys & Games $806.60 380 2.5 51 BULK-f0c667c2
18169 Bulk Product 8fccfba2 Home & Garden $382.22 491 4.4 39 BULK-3624a527
18170 Bulk Product 122a8ca6 Electronics $433.94 218 0.8 79 BULK-2c49be6d
18171 Bulk Product a38e76cb Electronics $383.55 84 1.2 4 BULK-dcccde71
18172 Bulk Product 4aa60621 Books $999.54 74 0.8 17 BULK-76561473
18173 Bulk Product d9458541 Electronics $855.06 316 3.7 66 BULK-77d109e9
18174 Bulk Product c8295ffc Sports & Outdoors $949.06 357 2.2 62 BULK-0aa16e5a
18175 Bulk Product 3730d9c0 Sports & Outdoors $205.93 29 4.2 73 BULK-ca882b8b
18176 Bulk Product b79f9cb9 Sports & Outdoors $398.52 487 4.3 10 BULK-fc04f29f
18177 Bulk Product b66c9b6d Clothing $887.76 370 0.2 9 BULK-dd790177
18178 Bulk Product a17475c9 Books $620.34 294 2.8 62 BULK-8cba4145
18179 Bulk Product 5a4bf7a9 Home & Garden $425.03 110 4.0 3 BULK-289f15b7
18180 Bulk Product dd5a4d13 Sports & Outdoors $712.29 115 4.4 61 BULK-4dbe2f5d
18181 Bulk Product 61162edf Toys & Games $89.49 217 2.0 86 BULK-cf6b5119
18182 Bulk Product c985f5d0 Sports & Outdoors $76.56 16 0.5 69 BULK-ad402dbb
18183 Bulk Product 0d1f47fe Books $151.34 203 3.9 11 BULK-0d007d5f
18184 Bulk Product d42b2cf2 Sports & Outdoors $453.79 8 2.5 90 BULK-368befc5
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