From 94bff5a4c35321bad4e1c4a86793a5fd3026f43f Mon Sep 17 00:00:00 2001 From: Andriy Svyryd Date: Thu, 26 Oct 2023 15:02:48 -0700 Subject: [PATCH] Revert binary breaking change on IEntityType (#32166) Fixes #32105 --- src/EFCore/Metadata/IEntityType.cs | 93 ++++++++++++++++++++++ src/EFCore/Metadata/Internal/EntityType.cs | 36 +++++++++ src/EFCore/Metadata/RuntimeEntityType.cs | 21 +++++ src/EFCore/Metadata/RuntimeTypeBase.cs | 9 ++- 4 files changed, 158 insertions(+), 1 deletion(-) diff --git a/src/EFCore/Metadata/IEntityType.cs b/src/EFCore/Metadata/IEntityType.cs index 0d334942a20..a665f190698 100644 --- a/src/EFCore/Metadata/IEntityType.cs +++ b/src/EFCore/Metadata/IEntityType.cs @@ -418,6 +418,99 @@ public interface IEntityType : IReadOnlyEntityType, ITypeBase /// The indexes defined on this entity type. new IEnumerable GetIndexes(); + // The following methods are needed for binary compatibility + #region DO NOT DELETE + + /// + /// Gets a property on the given entity type. Returns if no property is found. + /// + /// + /// This API only finds scalar properties and does not find navigation properties. Use + /// to find a navigation property. + /// + /// The property on the entity class. + /// The property, or if none is found. + new IProperty? FindProperty(MemberInfo memberInfo) + => (IProperty?)((IReadOnlyEntityType)this).FindProperty(memberInfo); + + /// + /// Gets the property with a given name. Returns if no property with the given name is defined. + /// + /// + /// This API only finds scalar properties and does not find navigation properties. Use + /// to find a navigation property. + /// + /// The name of the property. + /// The property, or if none is found. + new IProperty? FindProperty(string name); + + /// + /// Finds matching properties on the given entity type. Returns if any property is not found. + /// + /// + /// This API only finds scalar properties and does not find navigation properties. + /// + /// The property names. + /// The properties, or if any property is not found. + new IReadOnlyList? FindProperties( + IReadOnlyList propertyNames) + => (IReadOnlyList?)((IReadOnlyEntityType)this).FindProperties(propertyNames); + + /// + /// Gets a property with the given name. + /// + /// + /// This API only finds scalar properties and does not find navigation properties. Use + /// to find a navigation property. + /// + /// The property name. + /// The property. + new IProperty GetProperty(string name) + => (IProperty)((IReadOnlyEntityType)this).GetProperty(name); + + /// + /// Finds a property declared on the type with the given name. + /// Does not return properties defined on a base type. + /// + /// The property name. + /// The property, or if none is found. + new IProperty? FindDeclaredProperty(string name); + + /// + /// Gets all non-navigation properties declared on the given . + /// + /// + /// This method does not return properties declared on base types. + /// It is useful when iterating over all entity types to avoid processing the same property more than once. + /// Use to also return properties declared on base types. + /// + /// Declared non-navigation properties. + new IEnumerable GetDeclaredProperties(); + + /// + /// Gets all non-navigation properties declared on the types derived from this entity type. + /// + /// + /// This method does not return properties declared on the given entity type itself. + /// Use to return properties declared on this + /// and base entity typed types. + /// + /// Derived non-navigation properties. + new IEnumerable GetDerivedProperties() + => ((IReadOnlyEntityType)this).GetDerivedProperties().Cast(); + + /// + /// Gets the properties defined on this entity type. + /// + /// + /// This API only returns scalar properties and does not return navigation properties. Use + /// to get navigation properties. + /// + /// The properties defined on this entity type. + new IEnumerable GetProperties(); + + #endregion + /// /// Returns the properties contained in foreign keys. /// diff --git a/src/EFCore/Metadata/Internal/EntityType.cs b/src/EFCore/Metadata/Internal/EntityType.cs index b4dda1a09c1..3cbe2df7c1c 100644 --- a/src/EFCore/Metadata/Internal/EntityType.cs +++ b/src/EFCore/Metadata/Internal/EntityType.cs @@ -4104,6 +4104,42 @@ IEnumerable IEntityType.GetSkipNavigations() IConventionSkipNavigation? IConventionEntityType.RemoveSkipNavigation(IReadOnlySkipNavigation navigation) => RemoveSkipNavigation((SkipNavigation)navigation); + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + [DebuggerStepThrough] + IProperty? IEntityType.FindProperty(string name) => FindProperty(name); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + [DebuggerStepThrough] + IProperty? IEntityType.FindDeclaredProperty(string name) => FindDeclaredProperty(name); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + [DebuggerStepThrough] + IEnumerable IEntityType.GetDeclaredProperties() => GetDeclaredProperties(); + + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + [DebuggerStepThrough] + IEnumerable IEntityType.GetProperties() => GetProperties(); + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in diff --git a/src/EFCore/Metadata/RuntimeEntityType.cs b/src/EFCore/Metadata/RuntimeEntityType.cs index 09e847e831c..ace03b79a73 100644 --- a/src/EFCore/Metadata/RuntimeEntityType.cs +++ b/src/EFCore/Metadata/RuntimeEntityType.cs @@ -1258,6 +1258,27 @@ Func IRuntimeEntityType.RelationshipSnapshotFact ? new RelationshipSnapshotFactoryFactory().Create(entityType) : throw new InvalidOperationException(CoreStrings.NativeAotNoCompiledModel)); + /// + [DebuggerStepThrough] + IProperty? IEntityType.FindProperty(string name) => FindProperty(name); + + /// + [DebuggerStepThrough] + IReadOnlyList? IEntityType.FindProperties(IReadOnlyList propertyNames) + => FindProperties(propertyNames); + + /// + [DebuggerStepThrough] + IProperty? IEntityType.FindDeclaredProperty(string name) => FindDeclaredProperty(name); + + /// + [DebuggerStepThrough] + IEnumerable IEntityType.GetDeclaredProperties() => GetDeclaredProperties(); + + /// + [DebuggerStepThrough] + IEnumerable IEntityType.GetProperties() => GetProperties(); + /// [DebuggerStepThrough] IEnumerable IEntityType.GetForeignKeyProperties() diff --git a/src/EFCore/Metadata/RuntimeTypeBase.cs b/src/EFCore/Metadata/RuntimeTypeBase.cs index c54de0fc11f..64c8a1fcab4 100644 --- a/src/EFCore/Metadata/RuntimeTypeBase.cs +++ b/src/EFCore/Metadata/RuntimeTypeBase.cs @@ -230,7 +230,14 @@ public virtual RuntimeProperty AddProperty( public virtual RuntimeProperty? FindProperty(string name) => FindDeclaredProperty(name) ?? _baseType?.FindProperty(name); - private RuntimeProperty? FindDeclaredProperty(string name) + /// + /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to + /// the same compatibility standards as public APIs. It may be changed or removed without notice in + /// 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. + /// + [EntityFrameworkInternal] + protected virtual RuntimeProperty? FindDeclaredProperty(string name) => _properties.TryGetValue(name, out var property) ? property : null;