Skip to content

Commit

Permalink
Don't implement IModelFinalizingConvention on CosmosJsonIdConvention
Browse files Browse the repository at this point in the history
Fixes #34244
  • Loading branch information
AndriySvyryd committed Aug 2, 2024
1 parent 41e511f commit d58283d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
14 changes: 2 additions & 12 deletions src/EFCore.Cosmos/Metadata/Conventions/CosmosJsonIdConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public class CosmosJsonIdConvention
IPropertyRemovedConvention,
IPropertyAnnotationChangedConvention,
IModelAnnotationChangedConvention,
IDiscriminatorPropertySetConvention,
IModelFinalizingConvention
IDiscriminatorPropertySetConvention
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down Expand Up @@ -78,7 +77,7 @@ private void ProcessEntityType(IConventionEntityType entityType, IConventionCont
var primaryKey = entityType.FindPrimaryKey();
if (entityType.BaseType != null // Requires: IEntityTypeBaseTypeChangedConvention
|| !entityType.IsDocumentRoot() // Requires: IEntityTypeAnnotationChangedConvention (ContainerName)
|| entityType.IsOwned() // Requires: IForeignKeyOwnershipChangedConvention, IForeignKeyRemovedConvention
|| entityType.GetForeignKeys().Any(fk => fk.IsOwnership) // Requires: IForeignKeyOwnershipChangedConvention, IForeignKeyRemovedConvention
|| primaryKey == null) // Requires: IKeyAddedConvention, IKeyRemovedConvention
{
// If the entity type is not a keyed, root document in the container, then it doesn't have an `id` mapping, so
Expand Down Expand Up @@ -331,13 +330,4 @@ public virtual void ProcessDiscriminatorPropertySet(
string? name,
IConventionContext<string?> context)
=> ProcessEntityType(entityTypeBuilder.Metadata, context);

/// <inheritdoc />
public virtual void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
foreach (var entityType in modelBuilder.Metadata.GetEntityTypes())
{
ProcessEntityType(entityType, context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class JsonIdDefinitionFactory : IJsonIdDefinitionFactory
public virtual IJsonIdDefinition? Create(IEntityType entityType)
{
var primaryKey = entityType.FindPrimaryKey();
if (entityType.IsOwned() || primaryKey == null)
if (entityType.GetForeignKeys().Any(fk => fk.IsOwnership) || primaryKey == null)
{
return null;
}
Expand Down

0 comments on commit d58283d

Please sign in to comment.