Beispiel #1
0
            public override IConventionAnnotation OnSkipNavigationAnnotationChanged(
                IConventionSkipNavigationBuilder navigationBuilder,
                string name,
                IConventionAnnotation annotation,
                IConventionAnnotation oldAnnotation)
            {
                if (navigationBuilder.Metadata.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _annotationConventionContext.ResetState(annotation);
                    foreach (var skipNavigationConvention in _conventionSet.SkipNavigationAnnotationChangedConventions)
                    {
                        if (navigationBuilder.Metadata.Builder != null &&
                            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);
            }
Beispiel #2
0
        /// <inheritdoc />
        public virtual void ProcessEntityTypeAnnotationChanged(
            IConventionEntityTypeBuilder entityTypeBuilder,
            string name,
            IConventionAnnotation annotation,
            IConventionAnnotation oldAnnotation,
            IConventionContext <IConventionAnnotation> context)
        {
            if (name == CosmosAnnotationNames.ContainerName &&
                (annotation?.Value == null ||
                 oldAnnotation?.Value == null))
            {
                ProcessIdProperty(entityTypeBuilder);
            }
            else if (name == CosmosAnnotationNames.PartitionKeyName)
            {
                var oldName = (string)oldAnnotation?.Value;
                if (oldName != null)
                {
                    var oldPartitionKeyProperty = entityTypeBuilder.Metadata.FindProperty(oldName);
                    if (oldPartitionKeyProperty != null)
                    {
                        foreach (var key in oldPartitionKeyProperty.GetContainingKeys().ToList())
                        {
                            key.DeclaringEntityType.Builder.HasNoKey(key);
                        }
                    }
                }

                ProcessIdProperty(entityTypeBuilder);
            }
        }
Beispiel #3
0
        /// <inheritdoc />
        public virtual void ProcessPropertyAnnotationChanged(
            IConventionPropertyBuilder propertyBuilder,
            string name,
            IConventionAnnotation annotation,
            IConventionAnnotation oldAnnotation,
            IConventionContext <IConventionAnnotation> context)
        {
            if (name == CosmosAnnotationNames.PropertyName &&
                (string)annotation?.Value == IdPropertyJsonName &&
                propertyBuilder.Metadata.Name != DefaultIdPropertyName)
            {
                var entityType = propertyBuilder.Metadata.DeclaringEntityType;

                var idProperty = entityType.FindProperty(DefaultIdPropertyName);
                if (idProperty != null)
                {
                    foreach (var key in idProperty.GetContainingKeys().ToList())
                    {
                        key.DeclaringEntityType.Builder.HasNoKey(key);
                    }
                }

                ProcessIdProperty(entityType.Builder);
            }
        }
            public override IConventionAnnotation OnPropertyAnnotationChanged(
                IConventionPropertyBuilder propertyBuilder,
                string name,
                IConventionAnnotation annotation,
                IConventionAnnotation oldAnnotation)
            {
                if (propertyBuilder.Metadata.Builder == null ||
                    propertyBuilder.Metadata.DeclaringEntityType.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _annotationConventionContext.ResetState(annotation);
                    foreach (var propertyConvention in _conventionSet.PropertyAnnotationChangedConventions)
                    {
                        propertyConvention.ProcessPropertyAnnotationChanged(
                            propertyBuilder, name, annotation, oldAnnotation, _annotationConventionContext);

                        if (_annotationConventionContext.ShouldStopProcessing())
                        {
                            return(_annotationConventionContext.Result);
                        }
                    }
                }

                return(annotation);
            }
 /// <summary>
 ///     Called after an annotation is changed on an entity type.
 /// </summary>
 /// <param name="entityTypeBuilder"> The builder for the entity type. </param>
 /// <param name="name"> The annotation name. </param>
 /// <param name="annotation"> The new annotation. </param>
 /// <param name="oldAnnotation"> The old annotation.  </param>
 /// <param name="context"> Additional information associated with convention execution. </param>
 public virtual void ProcessEntityTypeAnnotationChanged(
     IConventionEntityTypeBuilder entityTypeBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation,
     IConventionContext <IConventionAnnotation> context)
 {
     if (name == RelationalAnnotationNames.TableName)
     {
         var schema = entityTypeBuilder.Metadata.GetSchema();
         ProcessTableChanged(
             entityTypeBuilder,
             (string)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultTableName(),
             schema,
             entityTypeBuilder.Metadata.GetTableName(),
             schema);
     }
     else if (name == RelationalAnnotationNames.Schema)
     {
         var tableName = entityTypeBuilder.Metadata.GetTableName();
         ProcessTableChanged(
             entityTypeBuilder,
             tableName,
             (string)oldAnnotation?.Value ?? entityTypeBuilder.Metadata.GetDefaultSchema(),
             tableName,
             entityTypeBuilder.Metadata.GetSchema());
     }
 }
            public override IConventionAnnotation OnIndexAnnotationChanged(
                IConventionIndexBuilder indexBuilder,
                string name,
                IConventionAnnotation annotation,
                IConventionAnnotation oldAnnotation)
            {
                if (indexBuilder.Metadata.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _annotationConventionContext.ResetState(annotation);
                    foreach (var indexConvention in _conventionSet.IndexAnnotationChangedConventions)
                    {
                        indexConvention.ProcessIndexAnnotationChanged(
                            indexBuilder, name, annotation, oldAnnotation, _annotationConventionContext);
                        if (_annotationConventionContext.ShouldStopProcessing())
                        {
                            return(_annotationConventionContext.Result);
                        }
                    }
                }

                return(annotation);
            }
            public override IConventionAnnotation OnEntityTypeAnnotationChanged(
                IConventionEntityTypeBuilder entityTypeBuilder,
                string name,
                IConventionAnnotation annotation,
                IConventionAnnotation oldAnnotation)
            {
                using (_dispatcher.DelayConventions())
                {
                    _annotationConventionContext.ResetState(annotation);
                    foreach (var entityTypeConvention in _conventionSet.EntityTypeAnnotationChangedConventions)
                    {
                        if (entityTypeBuilder.Metadata.Builder == null)
                        {
                            return(null);
                        }

                        entityTypeConvention.ProcessEntityTypeAnnotationChanged(
                            entityTypeBuilder, name, annotation, oldAnnotation, _annotationConventionContext);
                        if (_annotationConventionContext.ShouldStopProcessing())
                        {
                            return(_annotationConventionContext.Result);
                        }
                    }
                }

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

                return(annotation);
            }
        /// <summary>
        ///     Called after an annotation is changed on a property.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property. </param>
        /// <param name="name"> The annotation name. </param>
        /// <param name="annotation"> The new annotation. </param>
        /// <param name="oldAnnotation"> The old annotation.  </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        public override void ProcessPropertyAnnotationChanged(
            IConventionPropertyBuilder propertyBuilder, string name, IConventionAnnotation annotation, IConventionAnnotation oldAnnotation,
            IConventionContext <IConventionAnnotation> context)
        {
            if (annotation == null ||
                oldAnnotation?.Value != null)
            {
                return;
            }

            var configurationSource = annotation.GetConfigurationSource();
            var fromDataAnnotation  = configurationSource != ConfigurationSource.Convention;

            switch (name)
            {
            case RelationalAnnotationNames.DefaultValue:
                if (propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null &&
                    propertyBuilder.HasDefaultValue(null, fromDataAnnotation) != null)
                {
                    context.StopProcessing();
                    return;
                }

                break;

            case RelationalAnnotationNames.DefaultValueSql:
                if (propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null &&
                    propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) != null)
                {
                    context.StopProcessing();
                    return;
                }

                break;

            case RelationalAnnotationNames.ComputedColumnSql:
                if (propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null &&
                    propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) != null)
                {
                    context.StopProcessing();
                    return;
                }

                break;

            case SqlServerAnnotationNames.ValueGenerationStrategy:
                if ((propertyBuilder.HasDefaultValue(null, fromDataAnnotation) == null
                     | propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) == null
                     | propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) == null) &&
                    propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) != null)
                {
                    context.StopProcessing();
                    return;
                }

                break;
            }

            base.ProcessPropertyAnnotationChanged(propertyBuilder, name, annotation, oldAnnotation, context);
        }
Beispiel #9
0
            public override IConventionAnnotation OnNavigationAnnotationChanged(
                IConventionRelationshipBuilder relationshipBuilder,
                IConventionNavigation navigation,
                string name,
                IConventionAnnotation annotation,
                IConventionAnnotation oldAnnotation)
            {
                if (relationshipBuilder.Metadata.Builder == null ||
                    relationshipBuilder.Metadata.GetNavigation(navigation.IsDependentToPrincipal()) != navigation)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _annotationConventionContext.ResetState(annotation);
                    foreach (var navigationConvention in _conventionSet.NavigationAnnotationChangedConventions)
                    {
                        navigationConvention.ProcessNavigationAnnotationChanged(
                            relationshipBuilder, navigation, name, annotation, oldAnnotation, _annotationConventionContext);
                        if (_annotationConventionContext.ShouldStopProcessing())
                        {
                            return(_annotationConventionContext.Result);
                        }
                    }
                }

                return(annotation);
            }
Beispiel #10
0
 public OnIndexAnnotationChangedNode(
     IConventionIndexBuilder indexBuilder, string name, IConventionAnnotation annotation, IConventionAnnotation oldAnnotation)
 {
     IndexBuilder  = indexBuilder;
     Name          = name;
     Annotation    = annotation;
     OldAnnotation = oldAnnotation;
 }
Beispiel #11
0
 public override IConventionAnnotation OnForeignKeyAnnotationChanged(
     IConventionRelationshipBuilder relationshipBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     Add(new OnForeignKeyAnnotationChangedNode(relationshipBuilder, name, annotation, oldAnnotation));
     return(annotation);
 }
Beispiel #12
0
 public override IConventionAnnotation OnModelAnnotationChanged(
     IConventionModelBuilder modelBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     Add(new OnModelAnnotationChangedNode(modelBuilder, name, annotation, oldAnnotation));
     return(annotation);
 }
Beispiel #13
0
 public override IConventionAnnotation OnSkipNavigationAnnotationChanged(
     IConventionSkipNavigationBuilder navigationBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     Add(new OnSkipNavigationAnnotationChangedNode(navigationBuilder, name, annotation, oldAnnotation));
     return(annotation);
 }
Beispiel #14
0
 public override IConventionAnnotation OnPropertyAnnotationChanged(
     IConventionPropertyBuilder propertyBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     Add(new OnPropertyAnnotationChangedNode(propertyBuilder, name, annotation, oldAnnotation));
     return(annotation);
 }
Beispiel #15
0
 public override IConventionAnnotation OnIndexAnnotationChanged(
     IConventionIndexBuilder indexBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     Add(new OnIndexAnnotationChangedNode(indexBuilder, name, annotation, oldAnnotation));
     return(annotation);
 }
Beispiel #16
0
 /// <summary>
 ///     Called after an annotation is changed on an entity type.
 /// </summary>
 /// <param name="entityTypeBuilder"> The builder for the entity type. </param>
 /// <param name="name"> The annotation name. </param>
 /// <param name="annotation"> The new annotation. </param>
 /// <param name="oldAnnotation"> The old annotation.  </param>
 /// <param name="context"> Additional information associated with convention execution. </param>
 public void ProcessEntityTypeAnnotationChanged(
     IConventionEntityTypeBuilder entityTypeBuilder, string name, IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation, IConventionContext <IConventionAnnotation> context)
 {
     if (name == CosmosAnnotationNames.ContainerName)
     {
         Process(entityTypeBuilder);
     }
 }
Beispiel #17
0
 public override IConventionAnnotation OnEntityTypeAnnotationChanged(
     IConventionEntityTypeBuilder entityTypeBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     Add(new OnEntityTypeAnnotationChangedNode(entityTypeBuilder, name, annotation, oldAnnotation));
     return(annotation);
 }
 /// <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 OnPropertyAnnotationChanged(
     [NotNull] IConventionPropertyBuilder propertyBuilder,
     [NotNull] string name,
     [CanBeNull] IConventionAnnotation annotation,
     [CanBeNull] IConventionAnnotation oldAnnotation)
 => _scope.OnPropertyAnnotationChanged(
     propertyBuilder,
     name,
     annotation,
     oldAnnotation);
 /// <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 OnIndexAnnotationChanged(
     [NotNull] IConventionIndexBuilder indexBuilder,
     [NotNull] string name,
     [CanBeNull] IConventionAnnotation annotation,
     [CanBeNull] IConventionAnnotation oldAnnotation)
 => _scope.OnIndexAnnotationChanged(
     indexBuilder,
     name,
     annotation,
     oldAnnotation);
 /// <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 OnForeignKeyAnnotationChanged(
     [NotNull] IConventionRelationshipBuilder relationshipBuilder,
     [NotNull] string name,
     [CanBeNull] IConventionAnnotation annotation,
     [CanBeNull] IConventionAnnotation oldAnnotation)
 => _scope.OnForeignKeyAnnotationChanged(
     relationshipBuilder,
     name,
     annotation,
     oldAnnotation);
 /// <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 OnEntityTypeAnnotationChanged(
     [NotNull] IConventionEntityTypeBuilder entityTypeBuilder,
     [NotNull] string name,
     [CanBeNull] IConventionAnnotation annotation,
     [CanBeNull] IConventionAnnotation oldAnnotation)
 => _scope.OnEntityTypeAnnotationChanged(
     entityTypeBuilder,
     name,
     annotation,
     oldAnnotation);
 /// <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 OnModelAnnotationChanged(
     [NotNull] IConventionModelBuilder modelBuilder,
     [NotNull] string name,
     [CanBeNull] IConventionAnnotation annotation,
     [CanBeNull] IConventionAnnotation oldAnnotation)
 => _scope.OnModelAnnotationChanged(
     modelBuilder,
     name,
     annotation,
     oldAnnotation);
Beispiel #23
0
 public OnPropertyAnnotationChangedNode(
     IConventionPropertyBuilder propertyBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     PropertyBuilder = propertyBuilder;
     Name            = name;
     Annotation      = annotation;
     OldAnnotation   = oldAnnotation;
 }
Beispiel #24
0
 public OnSkipNavigationAnnotationChangedNode(
     IConventionSkipNavigationBuilder navigationBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     NavigationBuilder = navigationBuilder;
     Name          = name;
     Annotation    = annotation;
     OldAnnotation = oldAnnotation;
 }
Beispiel #25
0
 public OnKeyAnnotationChangedNode(
     IConventionKeyBuilder keyBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     KeyBuilder    = keyBuilder;
     Name          = name;
     Annotation    = annotation;
     OldAnnotation = oldAnnotation;
 }
Beispiel #26
0
 public OnForeignKeyAnnotationChangedNode(
     IConventionRelationshipBuilder relationshipBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     RelationshipBuilder = relationshipBuilder;
     Name          = name;
     Annotation    = annotation;
     OldAnnotation = oldAnnotation;
 }
Beispiel #27
0
 public OnEntityTypeAnnotationChangedNode(
     IConventionEntityTypeBuilder entityTypeBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     EntityTypeBuilder = entityTypeBuilder;
     Name          = name;
     Annotation    = annotation;
     OldAnnotation = oldAnnotation;
 }
Beispiel #28
0
 public OnModelAnnotationChangedNode(
     IConventionModelBuilder modelBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation)
 {
     ModelBuilder  = modelBuilder;
     Name          = name;
     Annotation    = annotation;
     OldAnnotation = oldAnnotation;
 }
Beispiel #29
0
 /// <summary>
 ///     Called after an annotation is changed on an index.
 /// </summary>
 /// <param name="indexBuilder"> The builder for the index. </param>
 /// <param name="name"> The annotation name. </param>
 /// <param name="annotation"> The new annotation. </param>
 /// <param name="oldAnnotation"> The old annotation.  </param>
 /// <param name="context"> Additional information associated with convention execution. </param>
 public virtual void ProcessIndexAnnotationChanged(
     IConventionIndexBuilder indexBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation,
     IConventionContext <IConventionAnnotation> context)
 {
     if (name == SqlServerAnnotationNames.Clustered)
     {
         SetIndexFilter(indexBuilder);
     }
 }
 /// <summary>
 ///     Called after an annotation is changed on an index.
 /// </summary>
 /// <param name="indexBuilder"> The builder for the index. </param>
 /// <param name="name"> The annotation name. </param>
 /// <param name="annotation"> The new annotation. </param>
 /// <param name="oldAnnotation"> The old annotation.  </param>
 /// <param name="context"> Additional information associated with convention execution. </param>
 public virtual void ProcessIndexAnnotationChanged(
     IConventionIndexBuilder indexBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation,
     IConventionContext <IConventionAnnotation> context)
 {
     //if (name == AseAnnotationNames.Clustered)
     //{
     //    SetIndexFilter(indexBuilder);
     //}
 }