Skip to content

Missing .Include() entities with certain ordering and .Take() #53

@Crusader2010

Description

@Crusader2010

Hi,

I think there is an issue that prevents the inclusion of child entities in certain cases. Here's some example code:

var employees = context.Employees.AsNoTracking();

if (statusArray.Any()) employees = employees.Where(x => statusArray.Contains(x.Status));

var result = await employees.Search(x => x.LastName, x => x.FirstName)
.Containing(comparisonResult)
.ToRanked().OrderByDescending(x => x.Hits)
.Select(x => x.Item)
.Include(x => x.Child1).ThenInclude(x => x.Child11).ThenInclude(x => x.Child111)
.Include(x => x.Child2).ThenInclude(x => x.Child22).ThenInclude(x => x.Child222)
.Take(200)
.ToListAsync();

Suppose the number of lines in the "employees" variable is 1000 before the ranked search. The actual result from the query brings 200 entities but only some of them have the proper references to the "Child" sub-entities. All the others have them as NULL even though they are present in the database.

If I move the .Take(200) after the query brought all the results (so after the async call), the results are fine, but that defeats the purpose - I don't want to bring thousands of lines in memory and only then be able to limit their number in the result.

I've also tried moving the .Include() statements in other positions but it makes no difference. It seems to be an issue with the ToRanked() and Hits and .Take() applying the .Include() before the ordering and not after, thus resulting in entities without children.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions