Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

22 ms

Page Size

25

Current Page

785 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 785 Results Showing 19601 - 19625 of 24441

ID Name Category Price Stock Rating Reviews SKU
20160 Bulk Product 56e733b5 Books $719.27 266 4.6 42 BULK-fca746cb
20161 Bulk Product 3084a74f Sports & Outdoors $539.95 180 4.6 17 BULK-9b7598d6
20162 Bulk Product 196fcb39 Electronics $258.42 52 0.3 45 BULK-84ae65ce
20163 Bulk Product f57e22fd Home & Garden $530.05 344 4.3 93 BULK-2736c01a
20164 Bulk Product e328853e Toys & Games $482.20 486 1.4 86 BULK-e9c0da0f
20165 Bulk Product bdf0ac59 Home & Garden $980.79 361 4.6 2 BULK-9a99fe31
20166 Bulk Product 1ac3938c Electronics $778.70 312 4.2 13 BULK-f54c700e
20167 Bulk Product 525f84bb Books $629.09 375 3.1 29 BULK-b1d4b853
20168 Bulk Product 16bc30e9 Home & Garden $679.60 53 2.5 66 BULK-8e39a1a7
20169 Bulk Product 3cc5036a Electronics $120.73 315 1.3 34 BULK-d0ff6ff7
20170 Bulk Product d23dd8f0 Toys & Games $937.37 375 4.6 90 BULK-a8f4969f
20171 Bulk Product 85719566 Home & Garden $172.96 151 1.7 8 BULK-dad80c7f
20172 Bulk Product d62f265d Sports & Outdoors $577.89 104 2.6 79 BULK-623b90c9
20173 Bulk Product b87166e7 Clothing $638.15 479 1.8 79 BULK-b57fbb6d
20174 Bulk Product 5f96c456 Toys & Games $707.42 368 0.6 86 BULK-669b9f5c
20175 Bulk Product dfef0d84 Sports & Outdoors $462.63 315 4.9 18 BULK-4b8fc702
20176 Bulk Product 161eb337 Toys & Games $781.74 244 3.3 89 BULK-f3ca6abb
20177 Bulk Product 404b40c3 Electronics $107.44 108 3.5 27 BULK-eb0749e2
20178 Bulk Product c9056814 Books $764.21 81 0.9 26 BULK-f17bc993
20179 Bulk Product ee339645 Electronics $954.98 434 1.1 65 BULK-e445004e
20180 Bulk Product 9eca2c90 Books $714.48 152 4.3 65 BULK-20fad83b
20181 Bulk Product 708b5c75 Sports & Outdoors $988.35 68 2.1 86 BULK-ede196d5
20182 Bulk Product a0d24121 Books $708.22 306 3.1 69 BULK-c5170c13
20183 Bulk Product 2a466250 Electronics $48.17 322 0.8 23 BULK-b3b59428
20184 Bulk Product e7658c4a Sports & Outdoors $343.38 479 3.3 26 BULK-82c210c0
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