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 query does not extract and use partial hierarchical partition key #34553

Closed
ajcvickers opened this issue Aug 28, 2024 · 0 comments · Fixed by #34557
Closed

Cosmos query does not extract and use partial hierarchical partition key #34553

ajcvickers opened this issue Aug 28, 2024 · 0 comments · Fixed by #34557
Assignees
Labels
area-cosmos area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@ajcvickers
Copy link
Member

Query, where Region is the top-level partition key:

    var customers = await context
        .Set<Customer>()
        .Where(e => e.Id == id && e.Region == region)
        .ToListAsync();

SQL:

info: 8/28/2024 12:14:24.244 CosmosEventId.ExecutedReadNext[30102] (Microsoft.EntityFrameworkCore.Database.Command) 
      Executed ReadNext (260.3355 ms, 2.79 RU) ActivityId='206d1672-4891-47f3-a378-742711a1261b', Container='SomeDbContext', Partition='None', Parameters=[@__id_0='0e2ba07d-e248-42a7-9ba2-08dcc6ad40f4', @__region_1='Europe']
      SELECT VALUE c
      FROM root c
      WHERE ((c["Id"] = @__id_0) AND (c["Region"] = @__region_1))
Repro
using (var context = new SomeDbContext())
{
    await context.Database.EnsureDeletedAsync();
    await context.Database.EnsureCreatedAsync();

    var id = new Guid("0e2ba07d-e248-42a7-9ba2-08dcc6ad40f4");
    var region = "Europe";
    var country = "UK";

    var customers = await context
        .Set<Customer>()
        .Where(e => e.Id == id && e.Region == region)
        .ToListAsync();
}

public class SomeDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseCosmos(
                "https://localhost:8081",
                "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
                "EFDatabase")
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();

    protected override void OnModelCreating(ModelBuilder modelBuilder) 
        => modelBuilder
            .Entity<Customer>()
            .HasPartitionKey(e => new { e.Region, e.PrimaryCountry });
}

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; }
}
@roji roji added this to the 9.0.0 milestone Aug 28, 2024
roji added a commit to roji/efcore that referenced this issue Aug 28, 2024
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 28, 2024
roji added a commit to roji/efcore that referenced this issue Aug 28, 2024
@roji roji closed this as completed in a72420c Aug 28, 2024
roji added a commit to roji/efcore that referenced this issue Aug 28, 2024
roji added a commit that referenced this issue 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-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants