Missing .Include() entities with certain ordering and .Take()
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.