1 year ago

#387759

test-img

Athanasios Sioppidis

Unexpected results in Entity Framework Core when using Skip and Take with Include

I am trying to load related entities using EF Core and then paginate the results.

When I use the code shown below with let's say pageIndex=1 and pageSize=20, I get only two results:

var products = _context.IProductServices
                       .Include(p => p.ICatalogProductServices)
                           .ThenInclude(cl => cl.Catalog)
                       .Include(p => p.Category)
                           .ThenInclude(c => c.Parent).AsSplitQuery();

var paginatedProducts = await products.Skip((pageIndex - 1) * pageSize)
                                      .Take(pageSize).ToListAsync();

When I remove the include clauses, it works as expected and I get 20 results

var products = _context.IProductServices.AsSplitQuery();
var paginatedProducts = await products.Skip((pageIndex - 1) * pageSize)
                                      .Take(pageSize).ToListAsync();

Is this expected behaviour? It seems like Skip and Take don't work as expected. I am using Entity Framework Core 6.0.3 with SQL Server

sql-server

razor

entity-framework-core

0 Answers

Your Answer

Accepted video resources