Skip to content

Commit

Permalink
API Review changes for complex types
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd authored Jul 18, 2023
1 parent 5d9faf9 commit 24e12b4
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public virtual void ProcessPropertyAnnotationChanged(
}
}

ProcessIdProperty(declaringType.FundamentalEntityType.Builder);
ProcessIdProperty(declaringType.ContainingEntityType.Builder);
}
}
}
2 changes: 1 addition & 1 deletion src/EFCore.InMemory/Storage/Internal/InMemoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public InMemoryStore(IInMemoryTableFactory tableFactory)
public virtual InMemoryIntegerValueGenerator<TProperty> GetIntegerValueGenerator<TProperty>(
IProperty property)
{
var entityType = property.DeclaringType.FundamentalEntityType;
var entityType = property.DeclaringType.ContainingEntityType;
lock (_lock)
{
return EnsureTable(entityType).GetIntegerValueGenerator<TProperty>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
38 changes: 19 additions & 19 deletions src/EFCore.Relational/Extensions/RelationalTypeBaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public static class RelationalTypeBaseExtensions
/// <param name="typeBase">The type to get the table name for.</param>
/// <returns>The name of the table to which the type is mapped.</returns>
public static string? GetTableName(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetTableName();
=> typeBase.ContainingEntityType.GetTableName();

/// <summary>
/// Returns the database schema that contains the mapped table.
/// </summary>
/// <param name="typeBase">The type to get the schema for.</param>
/// <returns>The database schema that contains the mapped table.</returns>
public static string? GetSchema(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetSchema();
=> typeBase.ContainingEntityType.GetSchema();

/// <summary>
/// Returns the default mappings that the type would use.
Expand Down Expand Up @@ -61,15 +61,15 @@ public static IEnumerable<ITableMapping> GetTableMappings(this ITypeBase typeBas
/// <param name="typeBase">The type to get the view name for.</param>
/// <returns>The name of the view to which the type is mapped.</returns>
public static string? GetViewName(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetViewName();
=> typeBase.ContainingEntityType.GetViewName();

/// <summary>
/// Returns the database schema that contains the mapped view.
/// </summary>
/// <param name="typeBase">The type to get the view schema for.</param>
/// <returns>The database schema that contains the mapped view.</returns>
public static string? GetViewSchema(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetViewSchema();
=> typeBase.ContainingEntityType.GetViewSchema();

/// <summary>
/// Returns the views to which the type is mapped.
Expand All @@ -91,7 +91,7 @@ public static IEnumerable<IViewMapping> GetViewMappings(this ITypeBase typeBase)
/// <param name="typeBase">The type.</param>
/// <returns>The SQL string used to provide data for the type.</returns>
public static string? GetSqlQuery(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetSqlQuery();
=> typeBase.ContainingEntityType.GetSqlQuery();

/// <summary>
/// Returns the SQL string mappings.
Expand All @@ -113,7 +113,7 @@ public static IEnumerable<ISqlQueryMapping> GetSqlQueryMappings(this ITypeBase t
/// <param name="typeBase">The type to get the function name for.</param>
/// <returns>The name of the function to which the type is mapped.</returns>
public static string? GetFunctionName(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetFunctionName();
=> typeBase.ContainingEntityType.GetFunctionName();

/// <summary>
/// Returns the functions to which the type is mapped.
Expand All @@ -136,7 +136,7 @@ public static IEnumerable<IFunctionMapping> GetFunctionMappings(this ITypeBase t
/// <param name="typeBase">The type.</param>
/// <returns>The stored procedure to which the type is mapped.</returns>
public static IReadOnlyStoredProcedure? GetDeleteStoredProcedure(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetDeleteStoredProcedure();
=> typeBase.ContainingEntityType.GetDeleteStoredProcedure();

/// <summary>
/// Returns the stored procedure to which the type is mapped for deletes
Expand All @@ -145,7 +145,7 @@ public static IEnumerable<IFunctionMapping> GetFunctionMappings(this ITypeBase t
/// <param name="typeBase">The type.</param>
/// <returns>The stored procedure to which the type is mapped.</returns>
public static IStoredProcedure? GetDeleteStoredProcedure(this ITypeBase typeBase)
=> typeBase.FundamentalEntityType.GetDeleteStoredProcedure();
=> typeBase.ContainingEntityType.GetDeleteStoredProcedure();

/// <summary>
/// Returns the stored procedure to which the type is mapped for inserts
Expand All @@ -154,7 +154,7 @@ public static IEnumerable<IFunctionMapping> GetFunctionMappings(this ITypeBase t
/// <param name="typeBase">The type.</param>
/// <returns>The stored procedure to which the type is mapped.</returns>
public static IReadOnlyStoredProcedure? GetInsertStoredProcedure(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetInsertStoredProcedure();
=> typeBase.ContainingEntityType.GetInsertStoredProcedure();

/// <summary>
/// Returns the stored procedure to which the type is mapped for inserts
Expand All @@ -163,7 +163,7 @@ public static IEnumerable<IFunctionMapping> GetFunctionMappings(this ITypeBase t
/// <param name="typeBase">The type.</param>
/// <returns>The stored procedure to which the type is mapped.</returns>
public static IStoredProcedure? GetInsertStoredProcedure(this ITypeBase typeBase)
=> typeBase.FundamentalEntityType.GetInsertStoredProcedure();
=> typeBase.ContainingEntityType.GetInsertStoredProcedure();

/// <summary>
/// Returns the stored procedure to which the type is mapped for updates
Expand All @@ -172,7 +172,7 @@ public static IEnumerable<IFunctionMapping> GetFunctionMappings(this ITypeBase t
/// <param name="typeBase">The type.</param>
/// <returns>The stored procedure to which the type is mapped.</returns>
public static IReadOnlyStoredProcedure? GetUpdateStoredProcedure(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetUpdateStoredProcedure();
=> typeBase.ContainingEntityType.GetUpdateStoredProcedure();

/// <summary>
/// Returns the stored procedure to which the type is mapped for updates
Expand All @@ -181,7 +181,7 @@ public static IEnumerable<IFunctionMapping> GetFunctionMappings(this ITypeBase t
/// <param name="typeBase">The type.</param>
/// <returns>The stored procedure to which the type is mapped.</returns>
public static IStoredProcedure? GetUpdateStoredProcedure(this ITypeBase typeBase)
=> typeBase.FundamentalEntityType.GetUpdateStoredProcedure();
=> typeBase.ContainingEntityType.GetUpdateStoredProcedure();

/// <summary>
/// Returns the insert stored procedures to which the type is mapped.
Expand Down Expand Up @@ -229,7 +229,7 @@ public static IEnumerable<IStoredProcedureMapping> GetUpdateStoredProcedureMappi
/// <param name="typeBase">The type.</param>
/// <returns>The configured type mapping fragments.</returns>
public static IEnumerable<IReadOnlyEntityTypeMappingFragment> GetMappingFragments(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetMappingFragments();
=> typeBase.ContainingEntityType.GetMappingFragments();

/// <summary>
/// <para>
Expand All @@ -243,7 +243,7 @@ public static IEnumerable<IReadOnlyEntityTypeMappingFragment> GetMappingFragment
/// <param name="typeBase">The type.</param>
/// <returns>The configured type mapping fragments.</returns>
public static IEnumerable<IEntityTypeMappingFragment> GetMappingFragments(this ITypeBase typeBase)
=> typeBase.FundamentalEntityType.GetMappingFragments();
=> typeBase.ContainingEntityType.GetMappingFragments();

/// <summary>
/// <para>
Expand All @@ -260,7 +260,7 @@ public static IEnumerable<IEntityTypeMappingFragment> GetMappingFragments(this I
public static IEnumerable<IReadOnlyEntityTypeMappingFragment> GetMappingFragments(
this IReadOnlyTypeBase typeBase,
StoreObjectType storeObjectType)
=> typeBase.FundamentalEntityType.GetMappingFragments(storeObjectType);
=> typeBase.ContainingEntityType.GetMappingFragments(storeObjectType);

/// <summary>
/// <para>
Expand All @@ -277,7 +277,7 @@ public static IEnumerable<IReadOnlyEntityTypeMappingFragment> GetMappingFragment
public static IEnumerable<IEntityTypeMappingFragment> GetMappingFragments(
this ITypeBase typeBase,
StoreObjectType storeObjectType)
=> typeBase.FundamentalEntityType.GetMappingFragments(storeObjectType);
=> typeBase.ContainingEntityType.GetMappingFragments(storeObjectType);

/// <summary>
/// <para>
Expand All @@ -294,7 +294,7 @@ public static IEnumerable<IEntityTypeMappingFragment> GetMappingFragments(
public static IReadOnlyEntityTypeMappingFragment? FindMappingFragment(
this IReadOnlyTypeBase typeBase,
in StoreObjectIdentifier storeObject)
=> typeBase.FundamentalEntityType.FindMappingFragment(storeObject);
=> typeBase.ContainingEntityType.FindMappingFragment(storeObject);

/// <summary>
/// <para>
Expand All @@ -311,7 +311,7 @@ public static IEnumerable<IEntityTypeMappingFragment> GetMappingFragments(
public static IEntityTypeMappingFragment? FindMappingFragment(
this ITypeBase typeBase,
in StoreObjectIdentifier storeObject)
=> typeBase.FundamentalEntityType.FindMappingFragment(storeObject);
=> typeBase.ContainingEntityType.FindMappingFragment(storeObject);

#endregion

Expand All @@ -323,7 +323,7 @@ public static IEnumerable<IEntityTypeMappingFragment> GetMappingFragments(
/// <param name="typeBase">The type.</param>
/// <returns>The mapping strategy for the derived types.</returns>
public static string? GetMappingStrategy(this IReadOnlyTypeBase typeBase)
=> typeBase.FundamentalEntityType.GetMappingStrategy();
=> typeBase.ContainingEntityType.GetMappingStrategy();

#endregion Mapping strategy

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/StoreObjectIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public override IEnumerable<IAnnotation> 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
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Infrastructure/ModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Metadata/IComplexType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public interface IComplexType : IReadOnlyComplexType, ITypeBase
/// <summary>
/// Gets the entity type on which the complex property chain is declared.
/// </summary>
IEntityType ITypeBase.FundamentalEntityType
=> (IEntityType)((IReadOnlyComplexType)this).FundamentalEntityType;
IEntityType ITypeBase.ContainingEntityType
=> (IEntityType)((IReadOnlyComplexType)this).ContainingEntityType;
}
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/IConventionTypeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface IConventionTypeBase : IReadOnlyTypeBase, IConventionAnnotatable
/// <summary>
/// Gets this entity type or the one on which the complex property chain is declared.
/// </summary>
new IConventionEntityType FundamentalEntityType
new IConventionEntityType ContainingEntityType
=> (IConventionEntityType)this;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/IMutableTypeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface IMutableTypeBase : IReadOnlyTypeBase, IMutableAnnotatable
/// <summary>
/// Gets this entity type or the one on which the complex property chain is declared.
/// </summary>
new IMutableEntityType FundamentalEntityType
new IMutableEntityType ContainingEntityType
=> (IMutableEntityType)this;

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/EFCore/Metadata/IReadOnlyComplexType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ public interface IReadOnlyComplexType : IReadOnlyTypeBase
IReadOnlyComplexProperty ComplexProperty { get; }

/// <summary>
/// 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.
/// </summary>
/// <param name="targetType">Type to search for in declaration path.</param>
/// <param name="type">Type to search for in declaration path.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="targetType" /> is in declaration path of this type,
/// <see langword="true" /> if <paramref name="type" /> is one of the containing types for this complex type,
/// otherwise <see langword="false" />.
/// </returns>
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/IReadOnlyTypeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface IReadOnlyTypeBase : IReadOnlyAnnotatable
/// <summary>
/// Gets this entity type or the one on which the complex property chain is declared.
/// </summary>
IReadOnlyEntityType FundamentalEntityType
IReadOnlyEntityType ContainingEntityType
=> (IReadOnlyEntityType)this;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/ITypeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface ITypeBase : IReadOnlyTypeBase, IAnnotatable
/// <summary>
/// Gets this entity type or the one on which the complex property chain is declared.
/// </summary>
new IEntityType FundamentalEntityType
new IEntityType ContainingEntityType
=> (IEntityType)this;

/// <summary>
Expand Down
20 changes: 10 additions & 10 deletions src/EFCore/Metadata/Internal/ComplexType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
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()
};

Expand Down Expand Up @@ -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.
/// </summary>
IReadOnlyEntityType IReadOnlyTypeBase.FundamentalEntityType
IReadOnlyEntityType IReadOnlyTypeBase.ContainingEntityType
{
[DebuggerStepThrough]
get => FundamentalEntityType;
get => ContainingEntityType;
}

/// <summary>
Expand All @@ -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.
/// </summary>
IMutableEntityType IMutableTypeBase.FundamentalEntityType
IMutableEntityType IMutableTypeBase.ContainingEntityType
{
[DebuggerStepThrough]
get => FundamentalEntityType;
get => ContainingEntityType;
}

/// <summary>
Expand All @@ -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.
/// </summary>
IConventionEntityType IConventionTypeBase.FundamentalEntityType
IConventionEntityType IConventionTypeBase.ContainingEntityType
{
[DebuggerStepThrough]
get => FundamentalEntityType;
get => ContainingEntityType;
}

/// <summary>
Expand All @@ -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.
/// </summary>
IEntityType ITypeBase.FundamentalEntityType
IEntityType ITypeBase.ContainingEntityType
{
[DebuggerStepThrough]
get => FundamentalEntityType;
get => ContainingEntityType;
}

#endregion
Expand Down
Loading

0 comments on commit 24e12b4

Please sign in to comment.