Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address API Review feedback #16671

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/EFCore/Extensions/ConventionForeignKeyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public static class ConventionForeignKeyExtensions
/// <param name="foreignKey"> The foreign key. </param>
/// <param name="entityType"> One of the entity types related by the foreign key. </param>
/// <returns> The entity type related to the given one. </returns>
public static IConventionEntityType ResolveOtherEntityType(
public static IConventionEntityType GetRelatedEntityType(
[NotNull] this IConventionForeignKey foreignKey, [NotNull] IConventionEntityType entityType)
=> (IConventionEntityType)((IForeignKey)foreignKey).ResolveOtherEntityType(entityType);
=> (IConventionEntityType)((IForeignKey)foreignKey).GetRelatedEntityType(entityType);

/// <summary>
/// Returns a navigation associated with this foreign key.
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore/Extensions/ConventionModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ public static void AddOwned([NotNull] this IConventionModel model, [NotNull] Typ
/// Indicates whether the given entity type name is ignored.
/// </summary>
/// <param name="model"> The model to check for ignored type. </param>
/// <param name="name"> The name of the entity type that could be ignored. </param>
/// <param name="typeName"> The name of the entity type that could be ignored. </param>
/// <returns> <c>true</c> if the given entity type name is ignored. </returns>
public static bool IsIgnored([NotNull] this IConventionModel model, [NotNull] string name)
=> model.FindIgnoredConfigurationSource(name) != null;
public static bool IsIgnored([NotNull] this IConventionModel model, [NotNull] string typeName)
=> model.FindIgnoredConfigurationSource(typeName) != null;

/// <summary>
/// Indicates whether the given entity type is ignored.
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore/Extensions/ConventionTypeBaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public static class ConventionTypeBaseExtensions
/// Indicates whether the given member name is ignored.
/// </summary>
/// <param name="entityType"> The type to check the ignored member. </param>
/// <param name="name"> The name of the member that might be ignored. </param>
/// <param name="memberName"> The name of the member that might be ignored. </param>
/// <returns> <c>true</c> if the given member name is ignored. </returns>
public static bool IsIgnored([NotNull] this IConventionTypeBase entityType, [NotNull] string name)
=> entityType.FindIgnoredConfigurationSource(name) != null;
public static bool IsIgnored([NotNull] this IConventionTypeBase entityType, [NotNull] string memberName)
=> entityType.FindIgnoredConfigurationSource(memberName) != null;

/// <summary>
/// <para>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Extensions/ForeignKeyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class ForeignKeyExtensions
/// <param name="foreignKey"> The foreign key. </param>
/// <param name="entityType"> One of the entity types related by the foreign key. </param>
/// <returns> The entity type related to the given one. </returns>
public static IEntityType ResolveOtherEntityType([NotNull] this IForeignKey foreignKey, [NotNull] IEntityType entityType)
public static IEntityType GetRelatedEntityType([NotNull] this IForeignKey foreignKey, [NotNull] IEntityType entityType)
{
if (foreignKey.DeclaringEntityType != entityType
&& foreignKey.PrincipalEntityType != entityType)
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Extensions/MutableForeignKeyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public static class MutableForeignKeyExtensions
/// <param name="foreignKey"> The foreign key. </param>
/// <param name="entityType"> One of the entity types related by the foreign key. </param>
/// <returns> The entity type related to the given one. </returns>
public static IMutableEntityType ResolveOtherEntityType(
public static IMutableEntityType GetRelatedEntityType(
[NotNull] this IMutableForeignKey foreignKey, [NotNull] IMutableEntityType entityType)
=> (IMutableEntityType)((IForeignKey)foreignKey).ResolveOtherEntityType(entityType);
=> (IMutableEntityType)((IForeignKey)foreignKey).GetRelatedEntityType(entityType);

/// <summary>
/// Returns a navigation associated with this foreign key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private static bool CanMergeWith(
{
var fk = existingNavigation.ForeignKey;
return (fk.IsSelfReferencing()
|| fk.ResolveOtherEntityType(existingNavigation.DeclaringEntityType) == inverseEntityTypeBuilder.Metadata)
|| fk.GetRelatedEntityType(existingNavigation.DeclaringEntityType) == inverseEntityTypeBuilder.Metadata)
&& fk.Builder.CanSetNavigation(inverse, !existingNavigation.IsDependentToPrincipal());
}

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/ForeignKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ public virtual IEnumerable<Navigation> FindNavigationsTo([NotNull] EntityType en
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual EntityType ResolveOtherEntityType([NotNull] EntityType entityType)
=> (EntityType)((IForeignKey)this).ResolveOtherEntityType(entityType);
=> (EntityType)((IForeignKey)this).GetRelatedEntityType(entityType);

// Note: This is set and used only by IdentityMapFactoryFactory, which ensures thread-safety
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Microsoft.EntityFrameworkCore.Query.Expressions.Internal;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query.NavigationExpansion;
using Microsoft.EntityFrameworkCore.Query.NavigationExpansion.Visitors;

namespace Microsoft.EntityFrameworkCore.Query.Pipeline
{
Expand Down Expand Up @@ -768,7 +767,8 @@ protected static Expression UnwrapLastNavigation(Expression expression)
: null);

protected static Expression Unwrap(Expression expression)
=> expression switch {
=> expression switch
{
EntityReferenceExpression wrapper => wrapper.Underlying,
LambdaExpression lambda when lambda.Body is EntityReferenceExpression wrapper =>
Expression.Lambda(
Expand All @@ -777,9 +777,9 @@ protected static Expression Unwrap(Expression expression)
lambda.TailCall,
lambda.Parameters),
_ => expression
};
};

public class EntityReferenceExpression : Expression
protected class EntityReferenceExpression : Expression
{
public override ExpressionType NodeType => ExpressionType.Extension;

Expand Down Expand Up @@ -900,7 +900,7 @@ public virtual void Print(ExpressionPrinter expressionPrinter)
}
}

public override string ToString() => $"{Underlying}[{(IsEntityType ? EntityType.ShortName(): "AnonymousObject")}{(SubqueryTraversed ? ", Subquery" : "")}]";
public override string ToString() => $"{Underlying}[{(IsEntityType ? EntityType.ShortName() : "AnonymousObject")}{(SubqueryTraversed ? ", Subquery" : "")}]";
}
}
}
24 changes: 12 additions & 12 deletions test/EFCore.Tests/Metadata/Internal/ForeignKeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ public void Can_find_targets_for_non_hierarchical_foreign_keys()
{
var fk = CreateOneToManyFK();

Assert.Same(fk.PrincipalEntityType, fk.ResolveOtherEntityType(fk.DeclaringEntityType));
Assert.Same(fk.DeclaringEntityType, fk.ResolveOtherEntityType(fk.PrincipalEntityType));
Assert.Same(fk.PrincipalEntityType, fk.GetRelatedEntityType(fk.DeclaringEntityType));
Assert.Same(fk.DeclaringEntityType, fk.GetRelatedEntityType(fk.PrincipalEntityType));
Assert.Equal(new[] { fk.PrincipalToDependent }, fk.FindNavigationsFrom(fk.PrincipalEntityType));
Assert.Equal(new[] { fk.DependentToPrincipal }, fk.FindNavigationsFrom(fk.DeclaringEntityType));
Assert.Equal(new[] { fk.DependentToPrincipal }, fk.FindNavigationsTo(fk.PrincipalEntityType));
Expand Down Expand Up @@ -622,8 +622,8 @@ public void Can_find_targets_for_same_base_foreign_keys()
var derivedDependent = model.AddEntityType(typeof(DerivedOneToManyDependent));
derivedDependent.BaseType = fk.DeclaringEntityType;

Assert.Same(fk.PrincipalEntityType, fk.ResolveOtherEntityType(fk.DeclaringEntityType));
Assert.Same(fk.DeclaringEntityType, fk.ResolveOtherEntityType(fk.PrincipalEntityType));
Assert.Same(fk.PrincipalEntityType, fk.GetRelatedEntityType(fk.DeclaringEntityType));
Assert.Same(fk.DeclaringEntityType, fk.GetRelatedEntityType(fk.PrincipalEntityType));
Assert.Same(fk.PrincipalToDependent, fk.FindNavigationsFrom(fk.PrincipalEntityType).SingleOrDefault());
Assert.Same(fk.DependentToPrincipal, fk.FindNavigationsFrom(fk.DeclaringEntityType).SingleOrDefault());
Assert.Same(fk.DependentToPrincipal, fk.FindNavigationsTo(fk.PrincipalEntityType).SingleOrDefault());
Expand All @@ -641,11 +641,11 @@ public void Can_find_targets_for_same_base_foreign_keys()
Assert.Equal(
CoreStrings.EntityTypeNotInRelationshipStrict(
derivedDependent.DisplayName(), fk.DeclaringEntityType.DisplayName(), fk.PrincipalEntityType.DisplayName()),
Assert.Throws<InvalidOperationException>(() => fk.ResolveOtherEntityType(derivedDependent)).Message);
Assert.Throws<InvalidOperationException>(() => fk.GetRelatedEntityType(derivedDependent)).Message);
Assert.Equal(
CoreStrings.EntityTypeNotInRelationshipStrict(
derivedPrincipal.DisplayName(), fk.DeclaringEntityType.DisplayName(), fk.PrincipalEntityType.DisplayName()),
Assert.Throws<InvalidOperationException>(() => fk.ResolveOtherEntityType(derivedPrincipal)).Message);
Assert.Throws<InvalidOperationException>(() => fk.GetRelatedEntityType(derivedPrincipal)).Message);
Assert.Equal(
CoreStrings.EntityTypeNotInRelationshipStrict(
derivedPrincipal.DisplayName(), fk.DeclaringEntityType.DisplayName(), fk.PrincipalEntityType.DisplayName()),
Expand Down Expand Up @@ -678,8 +678,8 @@ public void Can_find_targets_for_self_ref_foreign_keys()
{
var fk = CreateSelfRefFK();

Assert.Same(fk.PrincipalEntityType, fk.ResolveOtherEntityType(fk.DeclaringEntityType));
Assert.Same(fk.DeclaringEntityType, fk.ResolveOtherEntityType(fk.PrincipalEntityType));
Assert.Same(fk.PrincipalEntityType, fk.GetRelatedEntityType(fk.DeclaringEntityType));
Assert.Same(fk.DeclaringEntityType, fk.GetRelatedEntityType(fk.PrincipalEntityType));

Assert.Equal(
new[] { fk.PrincipalToDependent, fk.DependentToPrincipal },
Expand Down Expand Up @@ -713,8 +713,8 @@ public void Can_finding_targets_for_same_hierarchy_foreign_keys()
{
var fk = CreateOneToManySameHierarchyFK();

Assert.Same(fk.PrincipalEntityType, fk.ResolveOtherEntityType(fk.DeclaringEntityType));
Assert.Same(fk.DeclaringEntityType, fk.ResolveOtherEntityType(fk.PrincipalEntityType));
Assert.Same(fk.PrincipalEntityType, fk.GetRelatedEntityType(fk.DeclaringEntityType));
Assert.Same(fk.DeclaringEntityType, fk.GetRelatedEntityType(fk.PrincipalEntityType));
Assert.Same(fk.PrincipalToDependent, fk.FindNavigationsFrom(fk.PrincipalEntityType).SingleOrDefault());
Assert.Same(fk.DependentToPrincipal, fk.FindNavigationsFrom(fk.DeclaringEntityType).SingleOrDefault());
Assert.Same(fk.DependentToPrincipal, fk.FindNavigationsTo(fk.PrincipalEntityType).SingleOrDefault());
Expand Down Expand Up @@ -765,11 +765,11 @@ public void Finding_targets_throws_for_entity_types_not_in_the_relationship()
Assert.Equal(
CoreStrings.EntityTypeNotInRelationshipStrict(
unrelatedType.DisplayName(), fk.DeclaringEntityType.DisplayName(), fk.PrincipalEntityType.DisplayName()),
Assert.Throws<InvalidOperationException>(() => fk.ResolveOtherEntityType(unrelatedType)).Message);
Assert.Throws<InvalidOperationException>(() => fk.GetRelatedEntityType(unrelatedType)).Message);
Assert.Equal(
CoreStrings.EntityTypeNotInRelationshipStrict(
unrelatedType.DisplayName(), fk.DeclaringEntityType.DisplayName(), fk.PrincipalEntityType.DisplayName()),
Assert.Throws<InvalidOperationException>(() => fk.ResolveOtherEntityType(unrelatedType)).Message);
Assert.Throws<InvalidOperationException>(() => fk.GetRelatedEntityType(unrelatedType)).Message);

Assert.Equal(
CoreStrings.EntityTypeNotInRelationshipStrict(
Expand Down