Skip to content

Commit

Permalink
asfasf
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Oct 24, 2019
1 parent 937ab57 commit 680b887
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/EFCore/Metadata/Internal/InternalRelationshipBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ public virtual InternalRelationshipBuilder IsOwnership(bool? ownership, Configur
if (ownership.Value)
{
InternalRelationshipBuilder newRelationshipBuilder;
var otherOwnerships = declaringType.GetDeclaredForeignKeys().Where(fk => fk.IsOwnership).ToList();
var otherOwnership = declaringType.GetDeclaredForeignKeys().SingleOrDefault(fk => fk.IsOwnership);
var invertedOwnerships = declaringType.GetDeclaredReferencingForeignKeys()
.Where(fk => fk.IsOwnership && fk.DeclaringEntityType.ClrType == Metadata.PrincipalEntityType.ClrType).ToList();

Expand All @@ -1039,7 +1039,8 @@ public virtual InternalRelationshipBuilder IsOwnership(bool? ownership, Configur
Metadata.PrincipalToDependent == null
|| declaringType.DefiningNavigationName == Metadata.PrincipalToDependent.Name);

if (otherOwnerships.Any(fk => !configurationSource.Overrides(fk.GetConfigurationSource())))
if (otherOwnership != null
&& !configurationSource.Overrides(otherOwnership.GetConfigurationSource()))
{
return null;
}
Expand All @@ -1052,12 +1053,9 @@ public virtual InternalRelationshipBuilder IsOwnership(bool? ownership, Configur
return null;
}

foreach (var otherOwnership in otherOwnerships)
if (otherOwnership?.Builder != null)
{
if (otherOwnership.Builder != null)
{
otherOwnership.DeclaringEntityType.Builder.HasNoRelationship(otherOwnership, configurationSource);
}
otherOwnership.DeclaringEntityType.Builder.HasNoRelationship(otherOwnership, configurationSource);
}

foreach (var invertedOwnership in invertedOwnerships)
Expand All @@ -1071,7 +1069,7 @@ public virtual InternalRelationshipBuilder IsOwnership(bool? ownership, Configur
return newRelationshipBuilder;
}

if (otherOwnerships.Count > 0)
if (otherOwnership != null)
{
if (!Metadata.GetConfigurationSource().Overrides(ConfigurationSource.Explicit)
&& Metadata.PrincipalEntityType.IsInDefinitionPath(Metadata.DeclaringEntityType.ClrType))
Expand All @@ -1097,7 +1095,6 @@ public virtual InternalRelationshipBuilder IsOwnership(bool? ownership, Configur
var fk = newRelationshipBuilder.Metadata;
fk.DeclaringEntityType.Builder.HasNoRelationship(fk, fk.GetConfigurationSource());

var otherOwnership = otherOwnerships.Single();
if (otherOwnership.Builder.IsWeakTypeDefinition(configurationSource) == null)
{
return null;
Expand Down

0 comments on commit 680b887

Please sign in to comment.