diff --git a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs index eb8c3c01766..b5e7fb2c6bc 100644 --- a/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs +++ b/src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs @@ -154,6 +154,24 @@ static bool ExtractPartitionKeyFromPredicate( return true; } } + else if (joinCondition is MethodCallExpression + { + Method.Name: "Equals", + Object: null, + Arguments: [MethodCallExpression equalsMethodCallExpression, ParameterExpression parameterExpresion] + } + && equalsMethodCallExpression.TryGetEFPropertyArguments(out _, out var propertyName)) + { + var property = entityType.FindProperty(propertyName); + if (property == null) + { + return false; + } + + properties.Add(property); + parameterNames.Add(parameterExpresion.Name); + return true; + } return false; } diff --git a/test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs index c691be7f9f7..f4178ce5f16 100644 --- a/test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs @@ -1260,7 +1260,7 @@ public async Task Can_read_with_find_with_PK_partition_key() { var options = Fixture.CreateOptions(); - var customer = new Customer { Id = 42, Name = "Theon" }; + var customer = new CustomerGuid { Id = Guid.NewGuid(), Name = "Theon" }; await using (var context = new PartitionKeyContextPrimaryKey(options)) { @@ -1273,11 +1273,11 @@ public async Task Can_read_with_find_with_PK_partition_key() await using (var context = new PartitionKeyContextPrimaryKey(options)) { - var customerFromStore = context.Set().Find(42); + var customerFromStore = context.Set().Find(customer.Id); - Assert.Equal(42, customerFromStore.Id); + Assert.Equal(customer.Id, customerFromStore.Id); Assert.Equal("Theon", customerFromStore.Name); - AssertSql(context, @"ReadItem(42, 42)"); + AssertSql(context, @$"ReadItem({customer.Id}, {customer.Id})"); } } @@ -1404,11 +1404,10 @@ public PartitionKeyContextPrimaryKey(DbContextOptions dbContextOptions) } protected override void OnModelCreating(ModelBuilder modelBuilder) - => modelBuilder.Entity( + => modelBuilder.Entity( cb => { - cb.HasNoDiscriminator(); - cb.Property(c => c.Id).HasConversion(); + cb.Property(c => c.Id).ToJsonProperty("id"); cb.HasPartitionKey(c => c.Id); }); }