Skip to content

Commit

Permalink
Throw better exception for incorrect ownership configuration. (#18484)
Browse files Browse the repository at this point in the history
Fixes #13912
  • Loading branch information
AndriySvyryd authored Oct 21, 2019
1 parent ebb95a9 commit c480280
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ private IConventionRelationshipBuilder ConfigureInverseNavigation(
var ownership = entityType.FindOwnership();
if (ownership != null
&& ownership.PrincipalEntityType == targetEntityTypeBuilder.Metadata
&& ownership.PrincipalToDependent.GetIdentifyingMemberInfo() != inverseNavigationPropertyInfo)
&& ownership.PrincipalToDependent?.GetIdentifyingMemberInfo() != inverseNavigationPropertyInfo)
{
Dependencies.Logger.NonOwnershipInverseNavigationWarning(
entityType, navigationMemberInfo,
targetEntityTypeBuilder.Metadata, inverseNavigationPropertyInfo,
ownership.PrincipalToDependent.GetIdentifyingMemberInfo());
ownership.PrincipalToDependent?.GetIdentifyingMemberInfo());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private IReadOnlyList<RelationshipCandidate> FindRelationshipCandidates(IConvent
var targetOwnership = candidateTargetEntityType.FindOwnership();
if (targetOwnership != null
&& (targetOwnership.PrincipalEntityType != entityType
|| targetOwnership.PrincipalToDependent.Name != navigationPropertyInfo.GetSimpleMemberName())
|| targetOwnership.PrincipalToDependent?.Name != navigationPropertyInfo.GetSimpleMemberName())
&& (ownership == null
|| ownership.PrincipalEntityType != candidateTargetEntityType))
{
Expand Down Expand Up @@ -163,7 +163,7 @@ private IReadOnlyList<RelationshipCandidate> FindRelationshipCandidates(IConvent
&& (candidateTargetEntityType.IsOwned()
|| model.FindIsOwnedConfigurationSource(targetClrType) == null)
&& (ownership.PrincipalEntityType != candidateTargetEntityType
|| ownership.PrincipalToDependent.Name != inversePropertyInfo.GetSimpleMemberName()))
|| ownership.PrincipalToDependent?.Name != inversePropertyInfo.GetSimpleMemberName()))
|| (entityType.HasDefiningNavigation()
&& !candidateTargetEntityType.IsInDefinitionPath(entityType.ClrType)
&& (entityType.DefiningEntityType != candidateTargetEntityType
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2788,7 +2788,7 @@ public virtual InternalEntityTypeBuilder GetTargetEntityTypeBuilder(
if (existingOwnership != null
&& entityType.Model.IsOwned(targetClrType)
&& (existingOwnership.PrincipalEntityType != entityType
|| existingOwnership.PrincipalToDependent.Name != navigationInfo.GetSimpleMemberName()))
|| existingOwnership.PrincipalToDependent?.Name != navigationInfo.GetSimpleMemberName()))
{
return configurationSource.HasValue
&& !targetClrType.Equals(Metadata.ClrType)
Expand Down
Loading

0 comments on commit c480280

Please sign in to comment.