Skip to content

Commit

Permalink
Add quirk mode for #23516
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Dec 8, 2020
1 parent 99a93d2 commit 8c06b21
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,26 +1742,29 @@ public virtual InternalForeignKeyBuilder HasForeignKey(
[NotNull] EntityType dependentEntityType,
ConfigurationSource configurationSource)
{
using (var batch = Metadata.DeclaringEntityType.Model.ConventionDispatcher.DelayConventions())
using var batch = AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue23516", out var enabled) && enabled
? null
: Metadata.DeclaringEntityType.Model.ConventionDispatcher.DelayConventions();

var relationship = HasForeignKey(
dependentEntityType.Builder.GetOrCreateProperties(
propertyNames,
configurationSource,
Metadata.PrincipalKey.Properties,
Metadata.GetIsRequiredConfigurationSource() != null && Metadata.IsRequired,
Metadata.GetPrincipalKeyConfigurationSource() == null
&& Metadata.PrincipalEntityType.FindPrimaryKey() == null),
dependentEntityType,
configurationSource);

if (relationship == null)
{
var relationship = HasForeignKey(
dependentEntityType.Builder.GetOrCreateProperties(
propertyNames,
configurationSource,
Metadata.PrincipalKey.Properties,
Metadata.GetIsRequiredConfigurationSource() != null && Metadata.IsRequired,
Metadata.GetPrincipalKeyConfigurationSource() == null
&& Metadata.PrincipalEntityType.FindPrimaryKey() == null),
dependentEntityType,
configurationSource);

if (relationship == null)
{
return null;
}

return (InternalForeignKeyBuilder)batch.Run(relationship.Metadata)?.Builder;
return null;
}

return batch == null
? relationship
: (InternalForeignKeyBuilder)batch.Run(relationship.Metadata)?.Builder;
}

/// <summary>
Expand Down

0 comments on commit 8c06b21

Please sign in to comment.