admin管理员组

文章数量:1418371

If I explain a bit on my entities there is Routing entity. Then it has Steps in an one-to-many relationship.

public class Routing 
{
    public Guid Id { get; set; }
    public Guid? DriverId { get; set; }    
    public List<Step> Steps { get; set; }
}

public class Step 
{   
    public Guid Id { get; set; }   
    public Routing Routing { get; set; }
    public Guid? RoutingId { get; set; }
    public Guid? MenTaskId { get; set; }
    public MenTask MenTask { get; set; }
}

Here is my EF Core query that I'm executing for getting routing and all linked step data:

List<Routing> routes = await _Routing.GetQueryableAsync())
                                     .Include(x => x.Steps)
                                     .OrderBy(Sorting)
                                     .Skip(SkipCount)
                                     .Take(MaxResultCount)
                                     .ToList();

My question is, if I provide a MaxResultCount of 10, then it will not retrieve data for Steps array. But If I provide like 30 or above, then it will display steps data.

Then I try to google the issue and some says add below, and it didn't work.

foreach (var routing in routes)
{
    await _Routing.EnsureCollectionLoadedAsync(routing, x => x.Steps);
}

Some says to add .AsSplitQuery() before Skip() and Take, but that also won't work.

Any expert can guide me to trace the issue with above simple query?

本文标签: cAwkward behaviour with TAKE in EF Core queryStack Overflow