最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Awkward behaviour with TAKE in EF Core query - Stack Overflow

programmeradmin0浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论