From 24e12b4743b56f86c52033e7bcd9893f8231946a Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Tue, 18 Jul 2023 11:26:45 -0700 Subject: [PATCH] API Review changes for complex types --- .../Conventions/StoreKeyConvention.cs | 2 +- .../Storage/Internal/InMemoryStore.cs | 2 +- .../RelationalPropertyExtensions.cs | 2 +- .../RelationalTypeBaseExtensions.cs | 38 +++++++++---------- .../Metadata/StoreObjectIdentifier.cs | 2 +- .../Internal/SqliteAnnotationProvider.cs | 2 +- src/EFCore/Infrastructure/ModelValidator.cs | 2 +- .../ComplexPropertyDiscoveryConvention.cs | 2 +- .../PropertyDiscoveryConvention.cs | 5 --- src/EFCore/Metadata/IComplexType.cs | 4 +- src/EFCore/Metadata/IConventionTypeBase.cs | 2 +- src/EFCore/Metadata/IMutableTypeBase.cs | 2 +- src/EFCore/Metadata/IReadOnlyComplexType.cs | 10 ++--- src/EFCore/Metadata/IReadOnlyTypeBase.cs | 2 +- src/EFCore/Metadata/ITypeBase.cs | 2 +- src/EFCore/Metadata/Internal/ComplexType.cs | 20 +++++----- .../InternalComplexPropertyBuilder.cs | 6 +-- .../Metadata/Internal/PropertiesSnapshot.cs | 2 +- src/EFCore/Metadata/RuntimeComplexType.cs | 14 +++---- .../CSharpRuntimeModelCodeGeneratorTest.cs | 3 +- .../ModelBuilding/ComplexTypeTestBase.cs | 4 +- 21 files changed, 61 insertions(+), 67 deletions(-) diff --git a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs index 4dc7cc621e2..60c1ca92a2d 100644 --- a/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs +++ b/src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs @@ -306,7 +306,7 @@ public virtual void ProcessPropertyAnnotationChanged( } } - ProcessIdProperty(declaringType.FundamentalEntityType.Builder); + ProcessIdProperty(declaringType.ContainingEntityType.Builder); } } } diff --git a/src/EFCore.InMemory/Storage/Internal/InMemoryStore.cs b/src/EFCore.InMemory/Storage/Internal/InMemoryStore.cs index d6d001dc697..08ca15735f2 100644 --- a/src/EFCore.InMemory/Storage/Internal/InMemoryStore.cs +++ b/src/EFCore.InMemory/Storage/Internal/InMemoryStore.cs @@ -40,7 +40,7 @@ public InMemoryStore(IInMemoryTableFactory tableFactory) public virtual InMemoryIntegerValueGenerator GetIntegerValueGenerator( IProperty property) { - var entityType = property.DeclaringType.FundamentalEntityType; + var entityType = property.DeclaringType.ContainingEntityType; lock (_lock) { return EnsureTable(entityType).GetIntegerValueGenerator( diff --git a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs index f7e3d5affc4..e8fded6f6e6 100644 --- a/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs @@ -86,7 +86,7 @@ public static string GetColumnName(this IReadOnlyProperty property) } else { - var declaringEntityType = property.DeclaringType.FundamentalEntityType; + var declaringEntityType = property.DeclaringType.ContainingEntityType; if (declaringEntityType.GetMappingStrategy() != RelationalAnnotationNames.TpcMappingStrategy) { var declaringStoreObject = StoreObjectIdentifier.Create(property.DeclaringType, storeObject.StoreObjectType); diff --git a/src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs b/src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs index fb498fae9bf..a048935901b 100644 --- a/src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs @@ -21,7 +21,7 @@ public static class RelationalTypeBaseExtensions /// The type to get the table name for. /// The name of the table to which the type is mapped. public static string? GetTableName(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetTableName(); + => typeBase.ContainingEntityType.GetTableName(); /// /// Returns the database schema that contains the mapped table. @@ -29,7 +29,7 @@ public static class RelationalTypeBaseExtensions /// The type to get the schema for. /// The database schema that contains the mapped table. public static string? GetSchema(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetSchema(); + => typeBase.ContainingEntityType.GetSchema(); /// /// Returns the default mappings that the type would use. @@ -61,7 +61,7 @@ public static IEnumerable GetTableMappings(this ITypeBase typeBas /// The type to get the view name for. /// The name of the view to which the type is mapped. public static string? GetViewName(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetViewName(); + => typeBase.ContainingEntityType.GetViewName(); /// /// Returns the database schema that contains the mapped view. @@ -69,7 +69,7 @@ public static IEnumerable GetTableMappings(this ITypeBase typeBas /// The type to get the view schema for. /// The database schema that contains the mapped view. public static string? GetViewSchema(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetViewSchema(); + => typeBase.ContainingEntityType.GetViewSchema(); /// /// Returns the views to which the type is mapped. @@ -91,7 +91,7 @@ public static IEnumerable GetViewMappings(this ITypeBase typeBase) /// The type. /// The SQL string used to provide data for the type. public static string? GetSqlQuery(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetSqlQuery(); + => typeBase.ContainingEntityType.GetSqlQuery(); /// /// Returns the SQL string mappings. @@ -113,7 +113,7 @@ public static IEnumerable GetSqlQueryMappings(this ITypeBase t /// The type to get the function name for. /// The name of the function to which the type is mapped. public static string? GetFunctionName(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetFunctionName(); + => typeBase.ContainingEntityType.GetFunctionName(); /// /// Returns the functions to which the type is mapped. @@ -136,7 +136,7 @@ public static IEnumerable GetFunctionMappings(this ITypeBase t /// The type. /// The stored procedure to which the type is mapped. public static IReadOnlyStoredProcedure? GetDeleteStoredProcedure(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetDeleteStoredProcedure(); + => typeBase.ContainingEntityType.GetDeleteStoredProcedure(); /// /// Returns the stored procedure to which the type is mapped for deletes @@ -145,7 +145,7 @@ public static IEnumerable GetFunctionMappings(this ITypeBase t /// The type. /// The stored procedure to which the type is mapped. public static IStoredProcedure? GetDeleteStoredProcedure(this ITypeBase typeBase) - => typeBase.FundamentalEntityType.GetDeleteStoredProcedure(); + => typeBase.ContainingEntityType.GetDeleteStoredProcedure(); /// /// Returns the stored procedure to which the type is mapped for inserts @@ -154,7 +154,7 @@ public static IEnumerable GetFunctionMappings(this ITypeBase t /// The type. /// The stored procedure to which the type is mapped. public static IReadOnlyStoredProcedure? GetInsertStoredProcedure(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetInsertStoredProcedure(); + => typeBase.ContainingEntityType.GetInsertStoredProcedure(); /// /// Returns the stored procedure to which the type is mapped for inserts @@ -163,7 +163,7 @@ public static IEnumerable GetFunctionMappings(this ITypeBase t /// The type. /// The stored procedure to which the type is mapped. public static IStoredProcedure? GetInsertStoredProcedure(this ITypeBase typeBase) - => typeBase.FundamentalEntityType.GetInsertStoredProcedure(); + => typeBase.ContainingEntityType.GetInsertStoredProcedure(); /// /// Returns the stored procedure to which the type is mapped for updates @@ -172,7 +172,7 @@ public static IEnumerable GetFunctionMappings(this ITypeBase t /// The type. /// The stored procedure to which the type is mapped. public static IReadOnlyStoredProcedure? GetUpdateStoredProcedure(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetUpdateStoredProcedure(); + => typeBase.ContainingEntityType.GetUpdateStoredProcedure(); /// /// Returns the stored procedure to which the type is mapped for updates @@ -181,7 +181,7 @@ public static IEnumerable GetFunctionMappings(this ITypeBase t /// The type. /// The stored procedure to which the type is mapped. public static IStoredProcedure? GetUpdateStoredProcedure(this ITypeBase typeBase) - => typeBase.FundamentalEntityType.GetUpdateStoredProcedure(); + => typeBase.ContainingEntityType.GetUpdateStoredProcedure(); /// /// Returns the insert stored procedures to which the type is mapped. @@ -229,7 +229,7 @@ public static IEnumerable GetUpdateStoredProcedureMappi /// The type. /// The configured type mapping fragments. public static IEnumerable GetMappingFragments(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetMappingFragments(); + => typeBase.ContainingEntityType.GetMappingFragments(); /// /// @@ -243,7 +243,7 @@ public static IEnumerable GetMappingFragment /// The type. /// The configured type mapping fragments. public static IEnumerable GetMappingFragments(this ITypeBase typeBase) - => typeBase.FundamentalEntityType.GetMappingFragments(); + => typeBase.ContainingEntityType.GetMappingFragments(); /// /// @@ -260,7 +260,7 @@ public static IEnumerable GetMappingFragments(this I public static IEnumerable GetMappingFragments( this IReadOnlyTypeBase typeBase, StoreObjectType storeObjectType) - => typeBase.FundamentalEntityType.GetMappingFragments(storeObjectType); + => typeBase.ContainingEntityType.GetMappingFragments(storeObjectType); /// /// @@ -277,7 +277,7 @@ public static IEnumerable GetMappingFragment public static IEnumerable GetMappingFragments( this ITypeBase typeBase, StoreObjectType storeObjectType) - => typeBase.FundamentalEntityType.GetMappingFragments(storeObjectType); + => typeBase.ContainingEntityType.GetMappingFragments(storeObjectType); /// /// @@ -294,7 +294,7 @@ public static IEnumerable GetMappingFragments( public static IReadOnlyEntityTypeMappingFragment? FindMappingFragment( this IReadOnlyTypeBase typeBase, in StoreObjectIdentifier storeObject) - => typeBase.FundamentalEntityType.FindMappingFragment(storeObject); + => typeBase.ContainingEntityType.FindMappingFragment(storeObject); /// /// @@ -311,7 +311,7 @@ public static IEnumerable GetMappingFragments( public static IEntityTypeMappingFragment? FindMappingFragment( this ITypeBase typeBase, in StoreObjectIdentifier storeObject) - => typeBase.FundamentalEntityType.FindMappingFragment(storeObject); + => typeBase.ContainingEntityType.FindMappingFragment(storeObject); #endregion @@ -323,7 +323,7 @@ public static IEnumerable GetMappingFragments( /// The type. /// The mapping strategy for the derived types. public static string? GetMappingStrategy(this IReadOnlyTypeBase typeBase) - => typeBase.FundamentalEntityType.GetMappingStrategy(); + => typeBase.ContainingEntityType.GetMappingStrategy(); #endregion Mapping strategy diff --git a/src/EFCore.Relational/Metadata/StoreObjectIdentifier.cs b/src/EFCore.Relational/Metadata/StoreObjectIdentifier.cs index b58223a541b..967efd3f190 100644 --- a/src/EFCore.Relational/Metadata/StoreObjectIdentifier.cs +++ b/src/EFCore.Relational/Metadata/StoreObjectIdentifier.cs @@ -38,7 +38,7 @@ private StoreObjectIdentifier(StoreObjectType storeObjectType, string name, stri return viewName == null ? null : View(viewName, typeBase.GetViewSchema()); case StoreObjectType.SqlQuery: var query = typeBase.GetSqlQuery(); - return query == null ? null : SqlQuery(typeBase.FundamentalEntityType); + return query == null ? null : SqlQuery(typeBase.ContainingEntityType); case StoreObjectType.Function: var functionName = typeBase.GetFunctionName(); return functionName == null ? null : DbFunction(functionName); diff --git a/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationProvider.cs b/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationProvider.cs index 8aec3df3a1c..51aeb3bf830 100644 --- a/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationProvider.cs +++ b/src/EFCore.Sqlite.Core/Metadata/Internal/SqliteAnnotationProvider.cs @@ -67,7 +67,7 @@ public override IEnumerable For(IColumn column, bool designTime) // Model validation ensures that these facets are the same on all mapped properties var property = column.PropertyMappings.First().Property; // Only return auto increment for integer single column primary key - var primaryKey = property.DeclaringType.FundamentalEntityType.FindPrimaryKey(); + var primaryKey = property.DeclaringType.ContainingEntityType.FindPrimaryKey(); if (primaryKey is { Properties.Count: 1 } && primaryKey.Properties[0] == property && property.ValueGenerated == ValueGenerated.OnAdd diff --git a/src/EFCore/Infrastructure/ModelValidator.cs b/src/EFCore/Infrastructure/ModelValidator.cs index 7578b9f6618..2218b555d4c 100644 --- a/src/EFCore/Infrastructure/ModelValidator.cs +++ b/src/EFCore/Infrastructure/ModelValidator.cs @@ -245,7 +245,7 @@ void Validate(IConventionTypeBase typeBase) if (typeBase is not IConventionEntityType entityType) { - if (!((IReadOnlyComplexType)typeBase).IsInDeclarationPath(targetType)) + if (!((IReadOnlyComplexType)typeBase).IsContainedBy(targetType)) { throw new InvalidOperationException( CoreStrings.NavigationNotAddedComplexType( diff --git a/src/EFCore/Metadata/Conventions/ComplexPropertyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/ComplexPropertyDiscoveryConvention.cs index d8187c8e2c2..b7e0be26e4e 100644 --- a/src/EFCore/Metadata/Conventions/ComplexPropertyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/ComplexPropertyDiscoveryConvention.cs @@ -66,7 +66,7 @@ private bool TryConfigureComplexProperty(MemberInfo? candidateMember, IConventio var targetClrType = (elementType ?? candidateMember.GetMemberType()).UnwrapNullableType(); if (typeBase.Model.Builder.IsIgnored(targetClrType) || (typeBase is IReadOnlyComplexType complexType - && complexType.IsInDeclarationPath(targetClrType))) + && complexType.IsContainedBy(targetClrType))) { return false; } diff --git a/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs b/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs index 5526c48e9e8..78d27ecf6fe 100644 --- a/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs +++ b/src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs @@ -53,11 +53,6 @@ public void ProcessComplexPropertyAdded( complexType.Builder.Property(propertyInfo); } - if (!complexType.ClrType.IsValueType) - { - return; - } - foreach (var fieldInfo in complexType.GetRuntimeFields().Values) { if (!Dependencies.MemberClassifier.IsCandidatePrimitiveProperty(fieldInfo, model)) diff --git a/src/EFCore/Metadata/IComplexType.cs b/src/EFCore/Metadata/IComplexType.cs index 55d930d4d04..db4aaecd226 100644 --- a/src/EFCore/Metadata/IComplexType.cs +++ b/src/EFCore/Metadata/IComplexType.cs @@ -19,6 +19,6 @@ public interface IComplexType : IReadOnlyComplexType, ITypeBase /// /// Gets the entity type on which the complex property chain is declared. /// - IEntityType ITypeBase.FundamentalEntityType - => (IEntityType)((IReadOnlyComplexType)this).FundamentalEntityType; + IEntityType ITypeBase.ContainingEntityType + => (IEntityType)((IReadOnlyComplexType)this).ContainingEntityType; } diff --git a/src/EFCore/Metadata/IConventionTypeBase.cs b/src/EFCore/Metadata/IConventionTypeBase.cs index 3bfc0aad1a8..e502bd9d19c 100644 --- a/src/EFCore/Metadata/IConventionTypeBase.cs +++ b/src/EFCore/Metadata/IConventionTypeBase.cs @@ -34,7 +34,7 @@ public interface IConventionTypeBase : IReadOnlyTypeBase, IConventionAnnotatable /// /// Gets this entity type or the one on which the complex property chain is declared. /// - new IConventionEntityType FundamentalEntityType + new IConventionEntityType ContainingEntityType => (IConventionEntityType)this; /// diff --git a/src/EFCore/Metadata/IMutableTypeBase.cs b/src/EFCore/Metadata/IMutableTypeBase.cs index 8cec9ed78bb..6bbea096d44 100644 --- a/src/EFCore/Metadata/IMutableTypeBase.cs +++ b/src/EFCore/Metadata/IMutableTypeBase.cs @@ -29,7 +29,7 @@ public interface IMutableTypeBase : IReadOnlyTypeBase, IMutableAnnotatable /// /// Gets this entity type or the one on which the complex property chain is declared. /// - new IMutableEntityType FundamentalEntityType + new IMutableEntityType ContainingEntityType => (IMutableEntityType)this; /// diff --git a/src/EFCore/Metadata/IReadOnlyComplexType.cs b/src/EFCore/Metadata/IReadOnlyComplexType.cs index f127085ad6b..008da36c754 100644 --- a/src/EFCore/Metadata/IReadOnlyComplexType.cs +++ b/src/EFCore/Metadata/IReadOnlyComplexType.cs @@ -20,20 +20,20 @@ public interface IReadOnlyComplexType : IReadOnlyTypeBase IReadOnlyComplexProperty ComplexProperty { get; } /// - /// Gets a value indicating whether given type is in the complex type declaration path for this type. + /// Gets a value indicating whether given type is one of the containing types for this complex type. /// - /// Type to search for in declaration path. + /// Type to search for in declaration path. /// - /// if is in declaration path of this type, + /// if is one of the containing types for this complex type, /// otherwise . /// - bool IsInDeclarationPath(Type targetType) + bool IsContainedBy(Type type) { var currentType = this; while (currentType != null) { var declaringType = currentType.ComplexProperty.DeclaringType; - if (declaringType.ClrType.IsAssignableFrom(targetType)) + if (declaringType.ClrType.IsAssignableFrom(type)) { return true; } diff --git a/src/EFCore/Metadata/IReadOnlyTypeBase.cs b/src/EFCore/Metadata/IReadOnlyTypeBase.cs index 5d705b6b6c9..8d17bfc93e1 100644 --- a/src/EFCore/Metadata/IReadOnlyTypeBase.cs +++ b/src/EFCore/Metadata/IReadOnlyTypeBase.cs @@ -21,7 +21,7 @@ public interface IReadOnlyTypeBase : IReadOnlyAnnotatable /// /// Gets this entity type or the one on which the complex property chain is declared. /// - IReadOnlyEntityType FundamentalEntityType + IReadOnlyEntityType ContainingEntityType => (IReadOnlyEntityType)this; /// diff --git a/src/EFCore/Metadata/ITypeBase.cs b/src/EFCore/Metadata/ITypeBase.cs index 8d71a435a85..51d1a37805e 100644 --- a/src/EFCore/Metadata/ITypeBase.cs +++ b/src/EFCore/Metadata/ITypeBase.cs @@ -19,7 +19,7 @@ public interface ITypeBase : IReadOnlyTypeBase, IAnnotatable /// /// Gets this entity type or the one on which the complex property chain is declared. /// - new IEntityType FundamentalEntityType + new IEntityType ContainingEntityType => (IEntityType)this; /// diff --git a/src/EFCore/Metadata/Internal/ComplexType.cs b/src/EFCore/Metadata/Internal/ComplexType.cs index b9411a31c75..b72ccf3a1b0 100644 --- a/src/EFCore/Metadata/Internal/ComplexType.cs +++ b/src/EFCore/Metadata/Internal/ComplexType.cs @@ -105,11 +105,11 @@ protected override InternalTypeBaseBuilder BaseBuilder /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - public virtual EntityType FundamentalEntityType + public virtual EntityType ContainingEntityType => ComplexProperty.DeclaringType switch { EntityType entityType => entityType, - ComplexType declaringComplexType => declaringComplexType.FundamentalEntityType, + ComplexType declaringComplexType => declaringComplexType.ContainingEntityType, _ => throw new NotImplementedException() }; @@ -739,10 +739,10 @@ IMutableComplexProperty IMutableComplexType.ComplexProperty /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - IReadOnlyEntityType IReadOnlyTypeBase.FundamentalEntityType + IReadOnlyEntityType IReadOnlyTypeBase.ContainingEntityType { [DebuggerStepThrough] - get => FundamentalEntityType; + get => ContainingEntityType; } /// @@ -751,10 +751,10 @@ IReadOnlyEntityType IReadOnlyTypeBase.FundamentalEntityType /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - IMutableEntityType IMutableTypeBase.FundamentalEntityType + IMutableEntityType IMutableTypeBase.ContainingEntityType { [DebuggerStepThrough] - get => FundamentalEntityType; + get => ContainingEntityType; } /// @@ -763,10 +763,10 @@ IMutableEntityType IMutableTypeBase.FundamentalEntityType /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - IConventionEntityType IConventionTypeBase.FundamentalEntityType + IConventionEntityType IConventionTypeBase.ContainingEntityType { [DebuggerStepThrough] - get => FundamentalEntityType; + get => ContainingEntityType; } /// @@ -775,10 +775,10 @@ IConventionEntityType IConventionTypeBase.FundamentalEntityType /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - IEntityType ITypeBase.FundamentalEntityType + IEntityType ITypeBase.ContainingEntityType { [DebuggerStepThrough] - get => FundamentalEntityType; + get => ContainingEntityType; } #endregion diff --git a/src/EFCore/Metadata/Internal/InternalComplexPropertyBuilder.cs b/src/EFCore/Metadata/Internal/InternalComplexPropertyBuilder.cs index 8d792f89505..365528cb52a 100644 --- a/src/EFCore/Metadata/Internal/InternalComplexPropertyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalComplexPropertyBuilder.cs @@ -66,7 +66,7 @@ protected override InternalComplexPropertyBuilder This propertyBuilder.IsRequired(null, ConfigurationSource.Convention); List? detachedRelationships = null; - foreach (var relationshipToBeDetached in complexType.FundamentalEntityType.GetDeclaredForeignKeys().ToList()) + foreach (var relationshipToBeDetached in complexType.ContainingEntityType.GetDeclaredForeignKeys().ToList()) { if (!relationshipToBeDetached.Properties.Any(p => p.DeclaringType == complexType)) { @@ -84,7 +84,7 @@ protected override InternalComplexPropertyBuilder This } List<(InternalKeyBuilder, ConfigurationSource?)>? detachedKeys = null; - foreach (var keyToDetach in complexType.FundamentalEntityType.GetDeclaredKeys().ToList()) + foreach (var keyToDetach in complexType.ContainingEntityType.GetDeclaredKeys().ToList()) { if (!keyToDetach.Properties.Any(p => p.DeclaringType == complexType)) { @@ -125,7 +125,7 @@ protected override InternalComplexPropertyBuilder This } List? detachedIndexes = null; - foreach (var indexToBeDetached in complexType.FundamentalEntityType.GetDeclaredIndexes().ToList()) + foreach (var indexToBeDetached in complexType.ContainingEntityType.GetDeclaredIndexes().ToList()) { if (!indexToBeDetached.Properties.Any(p => p.DeclaringType == complexType)) { diff --git a/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs b/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs index 6d07cc0cccf..4c7db06c6a5 100644 --- a/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs +++ b/src/EFCore/Metadata/Internal/PropertiesSnapshot.cs @@ -105,7 +105,7 @@ public virtual void Attach(InternalTypeBaseBuilder typeBaseBuilder) } var entityTypeBuilder = typeBaseBuilder as InternalEntityTypeBuilder - ?? ((InternalComplexTypeBuilder)typeBaseBuilder).Metadata.FundamentalEntityType.Builder; + ?? ((InternalComplexTypeBuilder)typeBaseBuilder).Metadata.ContainingEntityType.Builder; if (Keys != null) { diff --git a/src/EFCore/Metadata/RuntimeComplexType.cs b/src/EFCore/Metadata/RuntimeComplexType.cs index 3151c62bf18..abc1633db47 100644 --- a/src/EFCore/Metadata/RuntimeComplexType.cs +++ b/src/EFCore/Metadata/RuntimeComplexType.cs @@ -38,10 +38,10 @@ public RuntimeComplexType( : base(name, type, complexProperty.DeclaringType.Model, null, changeTrackingStrategy, indexerPropertyInfo, propertyBag) { ComplexProperty = complexProperty; - FundamentalEntityType = complexProperty.DeclaringType switch + ContainingEntityType = complexProperty.DeclaringType switch { RuntimeEntityType entityType => entityType, - RuntimeComplexType declaringComplexType => declaringComplexType.FundamentalEntityType, + RuntimeComplexType declaringComplexType => declaringComplexType.ContainingEntityType, _ => throw new NotImplementedException() }; } @@ -60,7 +60,7 @@ public RuntimeComplexType( /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - private RuntimeEntityType FundamentalEntityType { get; } + private RuntimeEntityType ContainingEntityType { get; } /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -202,16 +202,16 @@ IComplexProperty IComplexType.ComplexProperty } /// - IReadOnlyEntityType IReadOnlyTypeBase.FundamentalEntityType + IReadOnlyEntityType IReadOnlyTypeBase.ContainingEntityType { [DebuggerStepThrough] - get => FundamentalEntityType; + get => ContainingEntityType; } /// - IEntityType ITypeBase.FundamentalEntityType + IEntityType ITypeBase.ContainingEntityType { [DebuggerStepThrough] - get => FundamentalEntityType; + get => ContainingEntityType; } } diff --git a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpRuntimeModelCodeGeneratorTest.cs b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpRuntimeModelCodeGeneratorTest.cs index 3f8a9a33f2f..d42bc38cbf0 100644 --- a/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpRuntimeModelCodeGeneratorTest.cs +++ b/test/EFCore.Design.Tests/Scaffolding/Internal/CSharpRuntimeModelCodeGeneratorTest.cs @@ -5883,8 +5883,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .IsRowVersion() .HasAnnotation("foo", "bar"); eb.Ignore(e => e.Context); - eb.ComplexProperty(o => o.Principal) - .Property(p => p.AlternateId); + eb.ComplexProperty(o => o.Principal); }); eb.ToTable("PrincipalBase"); diff --git a/test/EFCore.Tests/ModelBuilding/ComplexTypeTestBase.cs b/test/EFCore.Tests/ModelBuilding/ComplexTypeTestBase.cs index f982254c38d..6b6b3a53572 100644 --- a/test/EFCore.Tests/ModelBuilding/ComplexTypeTestBase.cs +++ b/test/EFCore.Tests/ModelBuilding/ComplexTypeTestBase.cs @@ -1481,7 +1481,7 @@ public virtual void Can_call_Property_on_a_field() var model = modelBuilder.FinalizeModel(); var complexType = model.FindEntityType(typeof(ComplexProperties)).GetComplexProperties().Single().ComplexType; - Assert.Equal(1, complexType.GetProperties().Count()); + Assert.Equal(3, complexType.GetProperties().Count()); var property = complexType.FindProperty(nameof(EntityWithFields.Id)); Assert.Null(property.PropertyInfo); Assert.NotNull(property.FieldInfo); @@ -1503,7 +1503,7 @@ public virtual void Can_ignore_a_field() var model = modelBuilder.FinalizeModel(); var complexProperty = model.FindEntityType(typeof(ComplexProperties)).GetComplexProperties().Single(); - Assert.Equal(1, complexProperty.ComplexType.GetProperties().Count()); + Assert.Equal(2, complexProperty.ComplexType.GetProperties().Count()); } [ConditionalFact]