public override IConventionAnnotation?OnSkipNavigationAnnotationChanged(
            IConventionSkipNavigationBuilder navigationBuilder,
            string name,
            IConventionAnnotation?annotation,
            IConventionAnnotation?oldAnnotation)
        {
            if (!navigationBuilder.Metadata.IsInModel)
            {
                return(null);
            }

            using (_dispatcher.DelayConventions())
            {
                _annotationConventionContext.ResetState(annotation);
                foreach (var skipNavigationConvention in _conventionSet.SkipNavigationAnnotationChangedConventions)
                {
                    if (navigationBuilder.Metadata.IsInModel &&
                        navigationBuilder.Metadata.FindAnnotation(name) != annotation)
                    {
                        Check.DebugAssert(false, "annotation removed");
                        return(null);
                    }

                    skipNavigationConvention.ProcessSkipNavigationAnnotationChanged(
                        navigationBuilder, name, annotation, oldAnnotation, _annotationConventionContext);
                    if (_annotationConventionContext.ShouldStopProcessing())
                    {
                        return(_annotationConventionContext.Result);
                    }
                }
            }

            return(annotation);
        }
Exemple #2
0
            public override IConventionSkipNavigationBuilder OnSkipNavigationAdded(
                IConventionSkipNavigationBuilder navigationBuilder)
            {
                if (navigationBuilder.Metadata.DeclaringEntityType.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _skipNavigationBuilderConventionContext.ResetState(navigationBuilder);
                    foreach (var skipNavigationConvention in _conventionSet.SkipNavigationAddedConventions)
                    {
                        if (navigationBuilder.Metadata.Builder == null)
                        {
                            Check.DebugAssert(false, "null builder");
                            return(null);
                        }

                        skipNavigationConvention.ProcessSkipNavigationAdded(navigationBuilder, _skipNavigationBuilderConventionContext);
                        if (_skipNavigationBuilderConventionContext.ShouldStopProcessing())
                        {
                            return(_skipNavigationBuilderConventionContext.Result);
                        }
                    }
                }

                if (navigationBuilder.Metadata.Builder == null)
                {
                    return(null);
                }

                return(navigationBuilder);
            }
 /// <inheritdoc />
 public override void ProcessSkipNavigationAdded(
     IConventionSkipNavigationBuilder skipNavigationBuilder,
     RequiredAttribute attribute,
     IConventionContext <IConventionSkipNavigationBuilder> context)
 {
     Dependencies.Logger.RequiredAttributeOnSkipNavigation(skipNavigationBuilder.Metadata);
 }
        public override IConventionForeignKey?OnSkipNavigationForeignKeyChanged(
            IConventionSkipNavigationBuilder navigationBuilder,
            IConventionForeignKey?foreignKey,
            IConventionForeignKey?oldForeignKey)
        {
            if (!navigationBuilder.Metadata.DeclaringEntityType.IsInModel)
            {
                return(null);
            }

            using (_dispatcher.DelayConventions())
            {
                _foreignKeyConventionContext.ResetState(foreignKey);
                foreach (var skipNavigationConvention in _conventionSet.SkipNavigationForeignKeyChangedConventions)
                {
                    skipNavigationConvention.ProcessSkipNavigationForeignKeyChanged(
                        navigationBuilder, foreignKey, oldForeignKey, _foreignKeyConventionContext);
                    if (_foreignKeyConventionContext.ShouldStopProcessing())
                    {
                        if (_foreignKeyConventionContext.Result != null)
                        {
                            // Preserve the old configuration to let the conventions finish processing them
                            _dispatcher.OnSkipNavigationForeignKeyChanged(navigationBuilder, foreignKey, oldForeignKey);
                        }

                        return(_foreignKeyConventionContext.Result);
                    }
                }
            }

            return(!navigationBuilder.Metadata.IsInModel ? null : foreignKey);
        }
Exemple #5
0
        public override IConventionSkipNavigationBuilder?OnSkipNavigationAdded(
            IConventionSkipNavigationBuilder navigationBuilder)
        {
            if (!navigationBuilder.Metadata.DeclaringEntityType.IsInModel)
            {
                return(null);
            }

            using (_dispatcher.DelayConventions())
            {
                _skipNavigationBuilderConventionContext.ResetState(navigationBuilder);
                foreach (var skipNavigationConvention in _conventionSet.SkipNavigationAddedConventions)
                {
                    if (!navigationBuilder.Metadata.IsInModel)
                    {
                        return(null);
                    }

                    skipNavigationConvention.ProcessSkipNavigationAdded(navigationBuilder, _skipNavigationBuilderConventionContext);
                    if (_skipNavigationBuilderConventionContext.ShouldStopProcessing())
                    {
                        return(_skipNavigationBuilderConventionContext.Result);
                    }
                }
            }

            if (!navigationBuilder.Metadata.IsInModel)
            {
                return(null);
            }

            return(navigationBuilder);
        }
 /// <inheritdoc />
 public override void ProcessSkipNavigationAdded(
     IConventionSkipNavigationBuilder skipNavigationBuilder,
     BackingFieldAttribute attribute,
     IConventionContext <IConventionSkipNavigationBuilder> context)
 {
     skipNavigationBuilder.HasField(attribute.Name, fromDataAnnotation: true);
 }
        public override IConventionSkipNavigation?OnSkipNavigationInverseChanged(
            IConventionSkipNavigationBuilder navigationBuilder,
            IConventionSkipNavigation?inverse,
            IConventionSkipNavigation?oldInverse)
        {
            if (!navigationBuilder.Metadata.DeclaringEntityType.IsInModel)
            {
                return(null);
            }

            using (_dispatcher.DelayConventions())
            {
                _skipNavigationConventionContext.ResetState(inverse);
                foreach (var skipNavigationConvention in _conventionSet.SkipNavigationInverseChangedConventions)
                {
                    skipNavigationConvention.ProcessSkipNavigationInverseChanged(
                        navigationBuilder, inverse, oldInverse, _skipNavigationConventionContext);
                    if (_skipNavigationConventionContext.ShouldStopProcessing())
                    {
                        return(_skipNavigationConventionContext.Result);
                    }
                }
            }

            return(!navigationBuilder.Metadata.IsInModel ? null : inverse);
        }
Exemple #8
0
        private void CreateJoinEntityType(IConventionSkipNavigationBuilder skipNavigationBuilder)
        {
            var skipNavigation = (SkipNavigation)skipNavigationBuilder.Metadata;

            if (skipNavigation.ForeignKey != null ||
                !skipNavigation.IsCollection)
            {
                return;
            }

            var inverseSkipNavigation = skipNavigation.Inverse;

            if (inverseSkipNavigation == null ||
                inverseSkipNavigation.ForeignKey != null ||
                !inverseSkipNavigation.IsCollection)
            {
                return;
            }

            Check.DebugAssert(inverseSkipNavigation.Inverse == skipNavigation,
                              "Inverse's inverse should be the original skip navigation");

            var declaringEntityType = skipNavigation.DeclaringEntityType;
            var inverseEntityType   = inverseSkipNavigation.DeclaringEntityType;
            var model = declaringEntityType.Model;

            var joinEntityTypeName = declaringEntityType.ShortName() + inverseEntityType.ShortName();

            if (model.FindEntityType(joinEntityTypeName) != null)
            {
                var otherIdentifiers = model.GetEntityTypes().ToDictionary(et => et.Name, et => 0);
                joinEntityTypeName = Uniquifier.Uniquify(
                    joinEntityTypeName,
                    otherIdentifiers,
                    int.MaxValue);
            }

            var joinEntityTypeBuilder = model.Builder.SharedTypeEntity(
                joinEntityTypeName, Model.DefaultPropertyBagType, ConfigurationSource.Convention);

            var leftForeignKey = CreateSkipNavigationForeignKey(skipNavigation, joinEntityTypeBuilder);

            if (leftForeignKey == null)
            {
                model.Builder.HasNoEntityType(joinEntityTypeBuilder.Metadata, ConfigurationSource.Convention);
                return;
            }

            var rightForeignKey = CreateSkipNavigationForeignKey(inverseSkipNavigation, joinEntityTypeBuilder);

            if (rightForeignKey == null)
            {
                model.Builder.HasNoEntityType(joinEntityTypeBuilder.Metadata, ConfigurationSource.Convention);
                return;
            }

            skipNavigation.Builder.HasForeignKey(leftForeignKey, ConfigurationSource.Convention);
            inverseSkipNavigation.Builder.HasForeignKey(rightForeignKey, ConfigurationSource.Convention);
        }
 public override IConventionForeignKey?OnSkipNavigationForeignKeyChanged(
     IConventionSkipNavigationBuilder navigationBuilder,
     IConventionForeignKey?foreignKey,
     IConventionForeignKey?oldForeignKey)
 {
     Add(new OnSkipNavigationForeignKeyChangedNode(navigationBuilder, foreignKey, oldForeignKey));
     return(foreignKey);
 }
Exemple #10
0
 /// <inheritdoc />
 public virtual void ProcessSkipNavigationForeignKeyChanged(
     IConventionSkipNavigationBuilder skipNavigationBuilder,
     IConventionForeignKey foreignKey,
     IConventionForeignKey oldForeignKey,
     IConventionContext <IConventionForeignKey> context)
 {
     foreignKey?.Builder?.OnDelete(GetTargetDeleteBehavior(foreignKey));
 }
 public override IConventionSkipNavigation?OnSkipNavigationInverseChanged(
     IConventionSkipNavigationBuilder navigationBuilder,
     IConventionSkipNavigation?inverse,
     IConventionSkipNavigation?oldInverse)
 {
     Add(new OnSkipNavigationInverseChangedNode(navigationBuilder, inverse, oldInverse));
     return(inverse);
 }
 /// <inheritdoc />
 public virtual void ProcessSkipNavigationInverseChanged(
     IConventionSkipNavigationBuilder skipNavigationBuilder,
     IConventionSkipNavigation?inverse,
     IConventionSkipNavigation?oldInverse,
     IConventionContext <IConventionSkipNavigation> context)
 {
     CreateJoinEntityType(skipNavigationBuilder);
 }
 public OnSkipNavigationForeignKeyChangedNode(
     IConventionSkipNavigationBuilder navigationBuilder,
     IConventionForeignKey?foreignKey,
     IConventionForeignKey?oldForeignKey)
 {
     NavigationBuilder = navigationBuilder;
     ForeignKey        = foreignKey;
     OldForeignKey     = oldForeignKey;
 }
 public OnSkipNavigationInverseChangedNode(
     IConventionSkipNavigationBuilder navigationBuilder,
     IConventionSkipNavigation?inverse,
     IConventionSkipNavigation?oldInverse)
 {
     NavigationBuilder = navigationBuilder;
     Inverse           = inverse;
     OldInverse        = oldInverse;
 }
Exemple #15
0
        /// <inheritdoc />
        public virtual void ProcessSkipNavigationAdded(
            IConventionSkipNavigationBuilder skipNavigationBuilder,
            IConventionContext <IConventionSkipNavigationBuilder> context)
        {
            Check.NotNull(skipNavigationBuilder, nameof(skipNavigationBuilder));
            Check.NotNull(context, nameof(context));

            CreateAssociationEntityType(skipNavigationBuilder);
        }
 public override IConventionAnnotation?OnSkipNavigationAnnotationChanged(
     IConventionSkipNavigationBuilder navigationBuilder,
     string name,
     IConventionAnnotation?annotation,
     IConventionAnnotation?oldAnnotation)
 {
     Add(new OnSkipNavigationAnnotationChangedNode(navigationBuilder, name, annotation, oldAnnotation));
     return(annotation);
 }
Exemple #17
0
        private void TryCreateJoinEntityType(IConventionSkipNavigationBuilder skipNavigationBuilder)
        {
            var skipNavigation = skipNavigationBuilder.Metadata;

            if (ShouldCreateJoinType(skipNavigation))
            {
                CreateJoinEntityType(GenerateJoinTypeName(skipNavigation), skipNavigation);
            }
        }
        /// <inheritdoc />
        public virtual void ProcessSkipNavigationAdded(
            IConventionSkipNavigationBuilder skipNavigationBuilder,
            IConventionContext <IConventionSkipNavigationBuilder> context)
        {
            var field = GetFieldToSet(skipNavigationBuilder.Metadata);

            if (field != null)
            {
                skipNavigationBuilder.HasField(field);
            }
        }
 public OnSkipNavigationAnnotationChangedNode(
     IConventionSkipNavigationBuilder navigationBuilder,
     string name,
     IConventionAnnotation?annotation,
     IConventionAnnotation?oldAnnotation)
 {
     NavigationBuilder = navigationBuilder;
     Name          = name;
     Annotation    = annotation;
     OldAnnotation = oldAnnotation;
 }
Exemple #20
0
 /// <inheritdoc />
 public virtual void ProcessSkipNavigationForeignKeyChanged(
     IConventionSkipNavigationBuilder skipNavigationBuilder,
     IConventionForeignKey?foreignKey,
     IConventionForeignKey?oldForeignKey,
     IConventionContext <IConventionForeignKey> context)
 {
     if (foreignKey is not null && foreignKey.IsInModel)
     {
         foreignKey.Builder.OnDelete(GetTargetDeleteBehavior(foreignKey));
     }
 }
Exemple #21
0
 public virtual void ProcessSkipNavigationForeignKeyChanged(
     IConventionSkipNavigationBuilder skipNavigationBuilder,
     IConventionForeignKey?foreignKey,
     IConventionForeignKey?oldForeignKey,
     IConventionContext <IConventionForeignKey> context)
 {
     if (foreignKey?.IsInModel == true &&
         foreignKey.GetPropertiesConfigurationSource() == null &&
         skipNavigationBuilder.Metadata.Inverse?.IsInModel == true)
     {
         DiscoverProperties(foreignKey.Builder, context);
     }
 }
Exemple #22
0
    /// <inheritdoc />
    public override void ProcessSkipNavigationForeignKeyChanged(
        IConventionSkipNavigationBuilder skipNavigationBuilder,
        IConventionForeignKey?foreignKey,
        IConventionForeignKey?oldForeignKey,
        IConventionContext <IConventionForeignKey> context)
    {
        base.ProcessSkipNavigationForeignKeyChanged(skipNavigationBuilder, foreignKey, oldForeignKey, context);

        if (oldForeignKey != null)
        {
            ProcessJoinPartitionKey(skipNavigationBuilder.Metadata);
        }
    }
        public virtual void ProcessSkipNavigationForeignKeyChanged(
            IConventionSkipNavigationBuilder skipNavigationBuilder,
            IConventionForeignKey?foreignKey,
            IConventionForeignKey?oldForeignKey,
            IConventionContext <IConventionForeignKey> context)
        {
            var joinEntityTypeBuilder = skipNavigationBuilder.Metadata.ForeignKey?.DeclaringEntityType.Builder;

            if (joinEntityTypeBuilder != null &&
                skipNavigationBuilder.Metadata.IsCollection)
            {
                TryConfigurePrimaryKey(joinEntityTypeBuilder);
            }
        }
Exemple #24
0
        public virtual void ProcessSkipNavigationInverseChanged(
            IConventionSkipNavigationBuilder skipNavigationBuilder,
            IConventionSkipNavigation?inverse,
            IConventionSkipNavigation?oldInverse,
            IConventionContext <IConventionSkipNavigation> context)
        {
            var foreignKey = skipNavigationBuilder.Metadata.ForeignKey;

            if (foreignKey != null &&
                foreignKey.GetPropertiesConfigurationSource() == null &&
                inverse?.IsInModel == true)
            {
                DiscoverProperties(foreignKey.Builder, context);
            }
        }
 /// <inheritdoc />
 public virtual void ProcessSkipNavigationAdded(
     IConventionSkipNavigationBuilder skipNavigationBuilder,
     IConventionContext<IConventionSkipNavigationBuilder> context)
 {
     var skipNavigation = skipNavigationBuilder.Metadata;
     var attributes = GetAttributes<TAttribute>(skipNavigation.DeclaringEntityType, skipNavigation);
     foreach (var attribute in attributes)
     {
         ProcessSkipNavigationAdded(skipNavigationBuilder, attribute, context);
         if (((IReadableConventionContext)context).ShouldStopProcessing())
         {
             break;
         }
     }
 }
        /// <inheritdoc />
        public virtual void ProcessSkipNavigationForeignKeyChanged(
            IConventionSkipNavigationBuilder skipNavigationBuilder,
            IConventionForeignKey foreignKey,
            IConventionForeignKey oldForeignKey,
            IConventionContext <IConventionForeignKey> context)
        {
            var joinEntityType = oldForeignKey?.DeclaringEntityType;
            var navigation     = skipNavigationBuilder.Metadata;

            if (joinEntityType?.Builder != null &&
                navigation.IsCollection &&
                navigation.ForeignKey?.DeclaringEntityType != joinEntityType)
            {
                ((InternalModelBuilder)joinEntityType.Model.Builder).RemoveImplicitJoinEntity((EntityType)joinEntityType);
            }
        }
Exemple #27
0
 /// <inheritdoc />
 public virtual void ProcessSkipNavigationForeignKeyChanged(
     IConventionSkipNavigationBuilder skipNavigationBuilder,
     IConventionForeignKey?foreignKey,
     IConventionForeignKey?oldForeignKey,
     IConventionContext <IConventionForeignKey> context)
 {
     if (foreignKey != null &&
         foreignKey.IsInModel)
     {
         var fkPropertiesToSet = FindCandidateDependentPropertiesThroughNavigation(skipNavigationBuilder.Metadata);
         if (fkPropertiesToSet != null)
         {
             foreignKey.Builder.HasForeignKey(fkPropertiesToSet, fromDataAnnotation: true);
         }
     }
 }
 /// <inheritdoc />
 public virtual void ProcessSkipNavigationForeignKeyChanged(
     IConventionSkipNavigationBuilder skipNavigationBuilder,
     IConventionForeignKey?foreignKey,
     IConventionForeignKey?oldForeignKey,
     IConventionContext <IConventionForeignKey> context)
 {
     if (skipNavigationBuilder.Metadata.JoinEntityType is IConventionEntityType joinEntityType &&
         joinEntityType.HasSharedClrType &&
         !joinEntityType.IsTemporal() &&
         joinEntityType.GetConfigurationSource() == ConfigurationSource.Convention &&
         skipNavigationBuilder.Metadata.DeclaringEntityType.IsTemporal() &&
         skipNavigationBuilder.Metadata.Inverse is IConventionSkipNavigation inverse &&
         inverse.DeclaringEntityType.IsTemporal())
     {
         joinEntityType.SetIsTemporal(true);
     }
 }
Exemple #29
0
        /// <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 IConventionAnnotation?OnSkipNavigationAnnotationChanged(
            IConventionSkipNavigationBuilder navigationBuilder,
            string name,
            IConventionAnnotation?annotation,
            IConventionAnnotation?oldAnnotation)
        {
            if (CoreAnnotationNames.AllNames.Contains(name))
            {
                return(annotation);
            }

            return(_scope.OnSkipNavigationAnnotationChanged(
                       navigationBuilder,
                       name,
                       annotation,
                       oldAnnotation));
        }
Exemple #30
0
        /// <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 IConventionAnnotation OnSkipNavigationAnnotationChanged(
            [NotNull] IConventionSkipNavigationBuilder navigationBuilder,
            [NotNull] string name,
            [CanBeNull] IConventionAnnotation annotation,
            [CanBeNull] IConventionAnnotation oldAnnotation)
        {
            if (CoreAnnotationNames.AllNames.Contains(name))
            {
                return(annotation);
            }

            return(_scope.OnSkipNavigationAnnotationChanged(
                       navigationBuilder,
                       name,
                       annotation,
                       oldAnnotation));
        }