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

Filtered Includes for hidden navigation properties #27493

Closed
mgraf1 opened this issue Feb 22, 2022 · 4 comments · Fixed by #28411
Closed

Filtered Includes for hidden navigation properties #27493

mgraf1 opened this issue Feb 22, 2022 · 4 comments · Fixed by #28411
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Milestone

Comments

@mgraf1
Copy link

mgraf1 commented Feb 22, 2022

Ask a question

Hello, I'm working on an application that uses EF Core to map DDD-style aggregates to a SQL Server database. Several aggregates have private collections which are treated as collections of owned entities. When I query these aggregates, I make use of string-based include statements to eagerly load the collections

var myObject = await this.context.MyObjects
    .Include("children")
    .FirstOrDefaultAsync(p => p.Id == myObjectId && EF.Property<int>(p, "tenantId") == tenantId);

This works very well. However I'd like to take advantage of the new filtered-include functionality to apply an order-by clause to children to ensure that children loaded from the database are always retrieved in a specific order.

Is there a way to do this for a private collection, or do I need to make children a public property and do something like:

var myObject = await this.context.MyObjects
    .Include(x => x.Children.OrderBy(c => c.Date))
    .FirstOrDefaultAsync(p => p.Id == myObjectId && EF.Property<int>(p, "tenantId") == tenantId);

Thanks!

@ajcvickers
Copy link
Contributor

There isn't currently a way to do this. In the future we could consider implementing something like this:

var posts = context.Posts.Include(e => EF.Property<Blog>(e, "Blog")).ToList();
var blogs = context.Blogs.Include(e => EF.Property<ICollection<Post>>(e, "Posts").OrderBy(c => c.Date)).ToList();

@smitpatel
Copy link
Contributor

This should be very easy to enable if we want to do it. Basically we would make c => c.Navigation as same as c => EF.Property<NavigationType>("Navigation") inside Include nodes.

@smitpatel smitpatel removed this from the Backlog milestone Mar 17, 2022
@mgraf1
Copy link
Author

mgraf1 commented Mar 17, 2022

In recent releases, EF Core has making big strides in allowing developers to create encapsulated domain models. IMO, this would be another win on that front since it removes the need to have a public navigation to leverage an important feature.

@ajcvickers
Copy link
Contributor

Design meeting for Navigation or Property.

@ajcvickers ajcvickers removed this from the Backlog milestone Jul 5, 2022
@ajcvickers ajcvickers assigned ajcvickers and unassigned maumar Jul 9, 2022
@ajcvickers ajcvickers added this to the 7.0.0 milestone Jul 9, 2022
@ajcvickers ajcvickers changed the title Filtered String-Based Includes Filtered Includes for hidden navigation properties Jul 10, 2022
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 10, 2022
ajcvickers added a commit that referenced this issue Jul 10, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview7 Jul 13, 2022
@ajcvickers ajcvickers removed this from the 7.0.0-preview7 milestone Nov 5, 2022
@ajcvickers ajcvickers added this to the 7.0.0 milestone Nov 5, 2022
@ajcvickers ajcvickers removed their assignment Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants