/// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual InternalSkipNavigationBuilder HasForeignKey(
            [CanBeNull] ForeignKey foreignKey,
            ConfigurationSource configurationSource)
        {
            if (!CanSetForeignKey(foreignKey, configurationSource))
            {
                return(null);
            }

            if (foreignKey != null)
            {
                foreignKey.UpdateConfigurationSource(configurationSource);

                if (Metadata.Inverse?.JoinEntityType != null &&
                    Metadata.Inverse.JoinEntityType
                    != (Metadata.IsOnDependent ? foreignKey.PrincipalEntityType : foreignKey.DeclaringEntityType))
                {
                    Metadata.Inverse.Builder.HasForeignKey(null, configurationSource);
                }
            }

            var oldForeignKey = Metadata.ForeignKey;

            Metadata.SetForeignKey(foreignKey, configurationSource);

            if (oldForeignKey?.Builder != null &&
                oldForeignKey != foreignKey &&
                oldForeignKey.ReferencingSkipNavigations?.Any() != true)
            {
                oldForeignKey.DeclaringEntityType.Builder.HasNoRelationship(oldForeignKey, ConfigurationSource.Convention);
            }

            return(this);
        }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual InternalSkipNavigationBuilder HasForeignKey([CanBeNull] ForeignKey foreignKey, ConfigurationSource configurationSource)
        {
            if (CanSetForeignKey(foreignKey, configurationSource))
            {
                if (foreignKey != null)
                {
                    foreignKey.UpdateConfigurationSource(configurationSource);
                }

                if (Metadata.AssociationEntityType != null &&
                    foreignKey?.DeclaringEntityType != Metadata.AssociationEntityType)
                {
                    // Have reset the foreign key of a skip navigation on one side of an
                    // association entity type to a different entity type. An implicit
                    // association entity type is only useful if both sides are
                    // configured - so, if it is implicit, remove that entity type
                    // (which will also remove the other skip navigation's foreign key).
                    Metadata.AssociationEntityType.Model.Builder.RemoveAssociationEntityIfCreatedImplicitly(
                        Metadata.AssociationEntityType, removeSkipNavigations: false, configurationSource);
                }

                Metadata.SetForeignKey(foreignKey, configurationSource);
                return(this);
            }

            return(null);
        }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual InternalSkipNavigationBuilder HasForeignKey([CanBeNull] ForeignKey foreignKey, ConfigurationSource configurationSource)
        {
            if (configurationSource.Overrides(Metadata.GetForeignKeyConfigurationSource()) ||
                Equals(Metadata.ForeignKey, foreignKey))
            {
                if (foreignKey != null)
                {
                    foreignKey.UpdateConfigurationSource(configurationSource);
                }

                Metadata.SetForeignKey(foreignKey, configurationSource);
                return(this);
            }

            return(null);
        }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual InternalSkipNavigationBuilder HasForeignKey([CanBeNull] ForeignKey foreignKey, ConfigurationSource configurationSource)
        {
            if (CanSetForeignKey(foreignKey, configurationSource))
            {
                if (foreignKey != null)
                {
                    foreignKey.UpdateConfigurationSource(configurationSource);

                    if (Metadata.Inverse?.JoinEntityType != null &&
                        Metadata.Inverse.JoinEntityType
                        != (Metadata.IsOnDependent ? foreignKey.PrincipalEntityType : foreignKey.DeclaringEntityType))
                    {
                        Metadata.Inverse.Builder.HasForeignKey(null, configurationSource);
                    }
                }

                Metadata.SetForeignKey(foreignKey, configurationSource);
                return(this);
            }

            return(null);
        }