Skip to content

Commit

Permalink
Unbreak API used by Scaffolding
Browse files Browse the repository at this point in the history
Add missing relational extentions
  • Loading branch information
AndriySvyryd committed Feb 24, 2021
1 parent 6e45ea2 commit 79c4e3a
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 51 deletions.
16 changes: 14 additions & 2 deletions src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ public static IEnumerable<IMutableForeignKey> FindRowInternalForeignKeys(
[NotNull] this IMutableEntityType entityType,
in StoreObjectIdentifier storeObject)
// ReSharper disable once RedundantCast
=> ((IEntityType)entityType).FindRowInternalForeignKeys(storeObject).Cast<IMutableForeignKey>();
=> ((IReadOnlyEntityType)entityType).FindRowInternalForeignKeys(storeObject).Cast<IMutableForeignKey>();

/// <summary>
/// Gets the foreign keys for the given entity type that point to other entity types
Expand All @@ -848,7 +848,19 @@ public static IEnumerable<IConventionForeignKey> FindRowInternalForeignKeys(
[NotNull] this IConventionEntityType entityType,
in StoreObjectIdentifier storeObject)
// ReSharper disable once RedundantCast
=> ((IEntityType)entityType).FindRowInternalForeignKeys(storeObject).Cast<IConventionForeignKey>();
=> ((IReadOnlyEntityType)entityType).FindRowInternalForeignKeys(storeObject).Cast<IConventionForeignKey>();

/// <summary>
/// Gets the foreign keys for the given entity type that point to other entity types
/// sharing the same table-like store object.
/// </summary>
/// <param name="entityType"> The entity type. </param>
/// <param name="storeObject"> The identifier of the store object. </param>
public static IEnumerable<IForeignKey> FindRowInternalForeignKeys(
[NotNull] this IEntityType entityType,
in StoreObjectIdentifier storeObject)
// ReSharper disable once RedundantCast
=> ((IReadOnlyEntityType)entityType).FindRowInternalForeignKeys(storeObject).Cast<IForeignKey>();

/// <summary>
/// Gets a value indicating whether the associated table is ignored by Migrations.
Expand Down
21 changes: 19 additions & 2 deletions src/EFCore.Relational/Extensions/RelationalForeignKeyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public static IEnumerable<IForeignKeyConstraint> GetMappedConstraints([NotNull]
public static IMutableForeignKey? FindSharedObjectRootForeignKey(
[NotNull] this IMutableForeignKey foreignKey,
in StoreObjectIdentifier storeObject)
=> (IMutableForeignKey?)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject);
=> (IMutableForeignKey?)((IReadOnlyForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject);

/// <summary>
/// <para>
Expand All @@ -281,6 +281,23 @@ public static IEnumerable<IForeignKeyConstraint> GetMappedConstraints([NotNull]
public static IConventionForeignKey? FindSharedObjectRootForeignKey(
[NotNull] this IConventionForeignKey foreignKey,
in StoreObjectIdentifier storeObject)
=> (IConventionForeignKey?)((IForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject);
=> (IConventionForeignKey?)((IReadOnlyForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject);

/// <summary>
/// <para>
/// Finds the first <see cref="IConventionForeignKey" /> that is mapped to the same constraint in a shared table-like object.
/// </para>
/// <para>
/// This method is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </para>
/// </summary>
/// <param name="foreignKey"> The foreign key. </param>
/// <param name="storeObject"> The identifier of the containing store object. </param>
/// <returns> The foreign key if found, or <see langword="null" /> if none was found.</returns>
public static IForeignKey? FindSharedObjectRootForeignKey(
[NotNull] this IForeignKey foreignKey,
in StoreObjectIdentifier storeObject)
=> (IForeignKey?)((IReadOnlyForeignKey)foreignKey).FindSharedObjectRootForeignKey(storeObject);
}
}
21 changes: 19 additions & 2 deletions src/EFCore.Relational/Extensions/RelationalIndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public static IEnumerable<ITableIndex> GetMappedTableIndexes([NotNull] this IInd
public static IMutableIndex? FindSharedObjectRootIndex(
[NotNull] this IMutableIndex index,
in StoreObjectIdentifier storeObject)
=> (IMutableIndex?)((IIndex)index).FindSharedObjectRootIndex(storeObject);
=> (IMutableIndex?)((IReadOnlyIndex)index).FindSharedObjectRootIndex(storeObject);

/// <summary>
/// <para>
Expand All @@ -352,6 +352,23 @@ public static IEnumerable<ITableIndex> GetMappedTableIndexes([NotNull] this IInd
public static IConventionIndex? FindSharedObjectRootIndex(
[NotNull] this IConventionIndex index,
in StoreObjectIdentifier storeObject)
=> (IConventionIndex?)((IIndex)index).FindSharedObjectRootIndex(storeObject);
=> (IConventionIndex?)((IReadOnlyIndex)index).FindSharedObjectRootIndex(storeObject);

/// <summary>
/// <para>
/// Finds the first <see cref="IConventionIndex" /> that is mapped to the same index in a shared table-like object.
/// </para>
/// <para>
/// This method is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </para>
/// </summary>
/// <param name="index"> The index. </param>
/// <param name="storeObject"> The identifier of the containing store object. </param>
/// <returns> The index found, or <see langword="null" /> if none was found.</returns>
public static IIndex? FindSharedObjectRootIndex(
[NotNull] this IIndex index,
in StoreObjectIdentifier storeObject)
=> (IIndex?)((IReadOnlyIndex)index).FindSharedObjectRootIndex(storeObject);
}
}
21 changes: 19 additions & 2 deletions src/EFCore.Relational/Extensions/RelationalKeyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static IEnumerable<IUniqueConstraint> GetMappedConstraints([NotNull] this
public static IMutableKey? FindSharedObjectRootKey(
[NotNull] this IMutableKey key,
in StoreObjectIdentifier storeObject)
=> (IMutableKey?)((IKey)key).FindSharedObjectRootKey(storeObject);
=> (IMutableKey?)((IReadOnlyKey)key).FindSharedObjectRootKey(storeObject);

/// <summary>
/// <para>
Expand All @@ -266,6 +266,23 @@ public static IEnumerable<IUniqueConstraint> GetMappedConstraints([NotNull] this
public static IConventionKey? FindSharedObjectRootKey(
[NotNull] this IConventionKey key,
in StoreObjectIdentifier storeObject)
=> (IConventionKey?)((IKey)key).FindSharedObjectRootKey(storeObject);
=> (IConventionKey?)((IReadOnlyKey)key).FindSharedObjectRootKey(storeObject);

/// <summary>
/// <para>
/// Finds the first <see cref="IConventionKey" /> that is mapped to the same constraint in a shared table-like object.
/// </para>
/// <para>
/// This method is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </para>
/// </summary>
/// <param name="key"> The key. </param>
/// <param name="storeObject"> The identifier of the containing store object. </param>
/// <returns> The key found, or <see langword="null" /> if none was found.</returns>
public static IKey? FindSharedObjectRootKey(
[NotNull] this IKey key,
in StoreObjectIdentifier storeObject)
=> (IKey?)((IReadOnlyKey)key).FindSharedObjectRootKey(storeObject);
}
}
47 changes: 47 additions & 0 deletions src/EFCore.Relational/Extensions/RelationalPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,23 @@ public static RelationalTypeMapping GetRelationalTypeMapping([NotNull] this IRea
in StoreObjectIdentifier storeObject)
=> (IConventionProperty?)FindSharedObjectRootProperty(property, storeObject);

/// <summary>
/// <para>
/// Finds the first <see cref="IProperty" /> that is mapped to the same column in a shared table-like object.
/// </para>
/// <para>
/// This method is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </para>
/// </summary>
/// <param name="property"> The property. </param>
/// <param name="storeObject"> The identifier of the table-like store object containing the column. </param>
/// <returns> The property found, or <see langword="null" /> if none was found.</returns>
public static IProperty? FindSharedStoreObjectRootProperty(
[NotNull] this IProperty property,
in StoreObjectIdentifier storeObject)
=> (IProperty?)FindSharedObjectRootProperty(property, storeObject);

private static IReadOnlyProperty? FindSharedObjectRootProperty([NotNull] IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
{
Check.NotNull(property, nameof(property));
Expand Down Expand Up @@ -1312,6 +1329,36 @@ public static RelationalTypeMapping GetRelationalTypeMapping([NotNull] this IRea
public static IReadOnlyAnnotatable? FindOverrides([NotNull] this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.Find(property, storeObject);

/// <summary>
/// <para>
/// Returns the property facet overrides for a particular table-like store object.
/// </para>
/// <para>
/// This method is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </para>
/// </summary>
/// <param name="property"> The property. </param>
/// <param name="storeObject"> The identifier of the table-like store object containing the column. </param>
/// <returns> An object that stores property facet overrides. </returns>
public static IAnnotatable? FindOverrides([NotNull] this IMutableProperty property, in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.Find(property, storeObject);

/// <summary>
/// <para>
/// Returns the property facet overrides for a particular table-like store object.
/// </para>
/// <para>
/// This method is typically used by database providers (and other extensions). It is generally
/// not used in application code.
/// </para>
/// </summary>
/// <param name="property"> The property. </param>
/// <param name="storeObject"> The identifier of the table-like store object containing the column. </param>
/// <returns> An object that stores property facet overrides. </returns>
public static IAnnotatable? FindOverrides([NotNull] this IConventionProperty property, in StoreObjectIdentifier storeObject)
=> RelationalPropertyOverrides.Find(property, storeObject);

/// <summary>
/// <para>
/// Returns the property facet overrides for a particular table-like store object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override void ProcessModelFinalizing(
}

#pragma warning disable CS0618 // Type or member is obsolete
var definingQuery = entityType.GetDefiningQuery();
var definingQuery = ((IEntityType)entityType).GetDefiningQuery();
if (definingQuery != null)
{
entityType.SetDefiningQuery((LambdaExpression)DbSetAccessRewriter.Rewrite(modelBuilder.Metadata, definingQuery));
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Extensions/ConventionEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class ConventionEntityTypeExtensions
/// <returns> The defining navigation if one exists or <see langword="null" /> otherwise. </returns>
[Obsolete("Entity types with defining navigations have been replaced by shared-type entity types")]
public static IConventionNavigation? FindDefiningNavigation([NotNull] this IConventionEntityType entityType)
=> (IConventionNavigation?)((IReadOnlyEntityType)entityType).FindDefiningNavigation();
=> (IConventionNavigation?)((IEntityType)entityType).FindDefiningNavigation();

/// <summary>
/// Sets the LINQ query used as the default source for queries of this type.
Expand Down
27 changes: 18 additions & 9 deletions src/EFCore/Extensions/EntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static class EntityTypeExtensions
/// <returns> The full name. </returns>
[DebuggerStepThrough]
[Obsolete("Use Name property")]
public static string FullName([NotNull] this IReadOnlyTypeBase type) => type.Name;
public static string FullName([NotNull] this ITypeBase type) => type.Name;

/// <summary>
/// Gets a value indicating whether this entity type has a defining navigation.
Expand All @@ -37,7 +37,7 @@ public static class EntityTypeExtensions
/// <returns> <see langword="true" /> if this entity type has a defining navigation. </returns>
[DebuggerStepThrough]
[Obsolete("Entity types with defining navigations have been replaced by shared-type entity types")]
public static bool HasDefiningNavigation([NotNull] this IReadOnlyEntityType entityType)
public static bool HasDefiningNavigation([NotNull] this IEntityType entityType)
=> entityType.HasDefiningNavigation();

/// <summary>
Expand All @@ -46,24 +46,33 @@ public static bool HasDefiningNavigation([NotNull] this IReadOnlyEntityType enti
/// <param name="entityType"> The entity type. </param>
/// <returns> The defining navigation if one exists or <see langword="null" /> otherwise. </returns>
[Obsolete("Entity types with defining navigations have been replaced by shared-type entity types")]
public static IReadOnlyNavigation? FindDefiningNavigation([NotNull] this IReadOnlyEntityType entityType)
public static INavigation? FindDefiningNavigation([NotNull] this IEntityType entityType)
{
if (!entityType.HasDefiningNavigation())
{
return null;
}

var definingNavigation = entityType.DefiningEntityType!.FindNavigation(entityType.DefiningNavigationName!);
var definingNavigation = (INavigation?)entityType.DefiningEntityType!.FindNavigation(entityType.DefiningNavigationName!);
return definingNavigation?.TargetEntityType == entityType ? definingNavigation : null;
}

/// <summary>
/// Gets all navigation properties on the given entity type.
/// </summary>
/// <param name="entityType"> The entity type. </param>
/// <returns> All navigation properties on the given entity type. </returns>
[Obsolete("Use IReadOnlyEntityType.GetNavigations")]
public static IEnumerable<INavigation> GetNavigations([NotNull] this IEntityType entityType)
=> entityType.GetNavigations();

/// <summary>
/// Gets the LINQ query used as the default source for queries of this type.
/// </summary>
/// <param name="entityType"> The entity type to get the defining query for. </param>
/// <returns> The LINQ query used as the default source. </returns>
[Obsolete("Use InMemoryEntityTypeExtensions.GetInMemoryQuery")]
public static LambdaExpression? GetDefiningQuery([NotNull] this IReadOnlyEntityType entityType)
public static LambdaExpression? GetDefiningQuery([NotNull] this IEntityType entityType)
{
Check.NotNull(entityType, nameof(entityType));

Expand All @@ -81,16 +90,16 @@ public static bool HasDefiningNavigation([NotNull] this IReadOnlyEntityType enti
/// or null if they have not common parent.
/// </returns>
[Obsolete("Use IReadOnlyEntityType.FindClosestCommonParent")]
public static IReadOnlyEntityType? GetClosestCommonParent(
[NotNull] this IReadOnlyEntityType entityType1, [NotNull] IReadOnlyEntityType entityType2)
=> entityType1.FindClosestCommonParent(entityType2);
public static IEntityType? GetClosestCommonParent(
[NotNull] this IEntityType entityType1, [NotNull] IEntityType entityType2)
=> (IEntityType?)entityType1.FindClosestCommonParent(entityType2);

/// <summary>
/// Returns the <see cref="IReadOnlyProperty" /> that will be used for storing a discriminator value.
/// </summary>
/// <param name="entityType"> The entity type. </param>
[Obsolete("Use IReadOnlyEntityType.FindDiscriminatorProperty")]
public static IReadOnlyProperty? GetDiscriminatorProperty([NotNull] this IReadOnlyEntityType entityType)
public static IProperty? GetDiscriminatorProperty([NotNull] this IEntityType entityType)
=> entityType.FindDiscriminatorProperty();
}
}
Loading

0 comments on commit 79c4e3a

Please sign in to comment.