Skip to content

Filtered Includes for hidden navigation properties #27493

Description

@mgraf1

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions