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

Cosmos: Projecting out owned entities retrieves the entire document #34067

Open
roji opened this issue Jun 22, 2024 · 3 comments · Fixed by #34315
Open

Cosmos: Projecting out owned entities retrieves the entire document #34067

roji opened this issue Jun 22, 2024 · 3 comments · Fixed by #34315
Assignees
Labels
area-cosmos area-perf area-query consider-for-next-release punted-for-9.0 Originally planned for the EF Core 9.0 (EF9) release, but moved out due to resource constraints. type-bug
Milestone

Comments

@roji
Copy link
Member

roji commented Jun 22, 2024

public virtual Task Project_owned_reference_navigation_which_owns_additional(bool async)
    => AssertQuery(
        async,
        ss => ss.Set<OwnedPerson>().OrderBy(o => o.Id).Select(p => p.PersonAddress));

Since PersonAddress owns further entity types (OwnedCountry), the expression inside the Select() contains IncludeExpression; this leads CosmosProjectionBindingExpressionVisitor into a specific path where we end up projecting the entire document. Compare how this works in relational - CosmosProjectionBindingExpressionVisitor is one place where Cosmos is still quite behind.

@roji roji added this to the 9.0.0 milestone Jun 22, 2024
@roji roji self-assigned this Jun 22, 2024
@roji roji changed the title Cosmos: Projecting out owned entities retrieves the entire document Cosmos: Projecting out owned entities which own additional entity types retrieves the entire document Jun 22, 2024
@ajcvickers ajcvickers added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. punted-for-9.0 Originally planned for the EF Core 9.0 (EF9) release, but moved out due to resource constraints. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels Jul 30, 2024
@ajcvickers ajcvickers modified the milestones: 9.0.0, Backlog Jul 31, 2024
@roji roji reopened this Aug 4, 2024
@roji
Copy link
Member Author

roji commented Aug 4, 2024

Not actually closed by #34355

@ajcvickers
Copy link
Member

@roji This is not limited to owned entities that have additional types. Projecting either an owned reference or collection results in bringing back the entire document. For example:

    await context
        .Set<Customer>()
        .AsNoTracking()
        .Select(e => e.Addresses)
        .ToListAsync();

    await context
        .Set<Customer>()
        .AsNoTracking()
        .Select(e => e.PhoneNumber)
        .ToListAsync();
info: 8/28/2024 12:33:56.712 CosmosEventId.ExecutingSqlQuery[30100] (Microsoft.EntityFrameworkCore.Database.Command) 
      Executing SQL query for container 'SomeDbContext' in partition 'None' [Parameters=[]]
      SELECT VALUE c
      FROM root c
info: 8/28/2024 12:33:56.719 CosmosEventId.ExecutedReadNext[30102] (Microsoft.EntityFrameworkCore.Database.Command) 
      Executed ReadNext (6.7595 ms, 2.25 RU) ActivityId='9616a1c2-9e2a-4858-a426-68e6001d2ac1', Container='SomeDbContext', Partition='None', Parameters=[]
      SELECT VALUE c
      FROM root c
public class Customer
{
    public Guid Id { get; set; }
    public required string Name { get; set; }
    public required string PrimaryCountry { get; set; }
    public required string Region { get; set; }
    public List<string>? Notes { get; set; }
    public Phone PhoneNumber { get; set; }
    public List<Address> Addresses { get; } = new();
}

public class Address
{
    public required string Street { get; set; }
    public required string City { get; set; }
    public required string Postcode { get; set; }
    public required string Country { get; set; }
}

public class Phone
{
    public required int CountryCode { get; set; }
    public required string Number { get; set; }
}

@roji
Copy link
Member Author

roji commented Aug 29, 2024

@ajcvickers understood and thanks for checking... I think this makes this even more important to fix (in 10).

@roji roji added the area-perf label Aug 29, 2024
@roji roji changed the title Cosmos: Projecting out owned entities which own additional entity types retrieves the entire document Cosmos: Projecting out owned entities retrieves the entire document Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-cosmos area-perf area-query consider-for-next-release punted-for-9.0 Originally planned for the EF Core 9.0 (EF9) release, but moved out due to resource constraints. type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants