Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Crusader2010 opened this issue Jul 12, 2024 · 0 comments
Open

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

Crusader2010 opened this issue Jul 12, 2024 · 0 comments

Comments

@Crusader2010
Copy link

Crusader2010 commented Jul 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant