public override IConventionIndexBuilder OnIndexAdded(IConventionIndexBuilder indexBuilder)
            {
                if (indexBuilder.Metadata.DeclaringEntityType.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _indexBuilderConventionContext.ResetState(indexBuilder);
                    foreach (var indexConvention in _conventionSet.IndexAddedConventions)
                    {
                        if (indexBuilder.Metadata.Builder == null)
                        {
                            return(null);
                        }

                        indexConvention.ProcessIndexAdded(indexBuilder, _indexBuilderConventionContext);
                        if (_indexBuilderConventionContext.ShouldStopProcessing())
                        {
                            return(_indexBuilderConventionContext.Result);
                        }
                    }
                }

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

                return(indexBuilder);
            }
            public override string OnEntityTypeIgnored(IConventionModelBuilder modelBuilder, string name, Type type)
            {
                using (_dispatcher.DelayConventions())
                {
                    _stringConventionContext.ResetState(name);
                    foreach (var entityTypeConvention in _conventionSet.EntityTypeIgnoredConventions)
                    {
                        if (!modelBuilder.Metadata.IsIgnored(name))
                        {
                            return(null);
                        }

                        entityTypeConvention.ProcessEntityTypeIgnored(modelBuilder, name, type, _stringConventionContext);
                        if (_stringConventionContext.ShouldStopProcessing())
                        {
                            return(_stringConventionContext.Result);
                        }
                    }
                }

                if (!modelBuilder.Metadata.IsIgnored(name))
                {
                    return(null);
                }

                return(name);
            }
            public override IConventionPropertyBuilder OnPropertyAdded(IConventionPropertyBuilder propertyBuilder)
            {
                if (propertyBuilder.Metadata.DeclaringEntityType.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _propertyBuilderConventionContext.ResetState(propertyBuilder);
                    foreach (var propertyConvention in _conventionSet.PropertyAddedConventions)
                    {
                        if (propertyBuilder.Metadata.Builder == null)
                        {
                            return(null);
                        }

                        propertyConvention.ProcessPropertyAdded(propertyBuilder, _propertyBuilderConventionContext);
                        if (_propertyBuilderConventionContext.ShouldStopProcessing())
                        {
                            return(_propertyBuilderConventionContext.Result);
                        }
                    }
                }

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

                return(propertyBuilder);
            }
Exemple #4
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);
            }
            public override IConventionKeyBuilder OnKeyAdded(IConventionKeyBuilder keyBuilder)
            {
                if (keyBuilder.Metadata.DeclaringEntityType.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _keyBuilderConventionContext.ResetState(keyBuilder);
                    foreach (var keyConvention in _conventionSet.KeyAddedConventions)
                    {
                        if (keyBuilder.Metadata.Builder == null)
                        {
                            return(null);
                        }

                        keyConvention.ProcessKeyAdded(keyBuilder, _keyBuilderConventionContext);
                        if (_keyBuilderConventionContext.ShouldStopProcessing())
                        {
                            return(_keyBuilderConventionContext.Result);
                        }
                    }
                }

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

                return(keyBuilder);
            }
            public override IConventionEntityTypeBuilder OnEntityTypeAdded(IConventionEntityTypeBuilder entityTypeBuilder)
            {
                using (_dispatcher.DelayConventions())
                {
                    _entityTypeBuilderConventionContext.ResetState(entityTypeBuilder);
                    foreach (var entityTypeConvention in _conventionSet.EntityTypeAddedConventions)
                    {
                        if (entityTypeBuilder.Metadata.Builder == null)
                        {
                            return(null);
                        }

                        entityTypeConvention.ProcessEntityTypeAdded(entityTypeBuilder, _entityTypeBuilderConventionContext);
                        if (_entityTypeBuilderConventionContext.ShouldStopProcessing())
                        {
                            return(_entityTypeBuilderConventionContext.Result);
                        }
                    }
                }

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

                return(entityTypeBuilder);
            }
            public override IConventionNavigation OnNavigationAdded(
                IConventionRelationshipBuilder relationshipBuilder, IConventionNavigation navigation)
            {
                if (relationshipBuilder.Metadata.Builder == null ||
                    relationshipBuilder.Metadata.GetNavigation(navigation.IsDependentToPrincipal()) != navigation)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _navigationConventionContext.ResetState(navigation);
                    foreach (var navigationConvention in _conventionSet.NavigationAddedConventions)
                    {
                        navigationConvention.ProcessNavigationAdded(relationshipBuilder, navigation, _navigationConventionContext);
                        if (_navigationConventionContext.ShouldStopProcessing())
                        {
                            return(_navigationConventionContext.Result);
                        }
                    }
                }

                if (relationshipBuilder.Metadata.GetNavigation(navigation.IsDependentToPrincipal()) != navigation)
                {
                    return(null);
                }

                return(navigation);
            }
Exemple #8
0
        private Navigation RunConvention(InternalRelationshipBuilder relationshipBuilder, Navigation navigation)
        {
            var context = new ConventionContext <IConventionNavigation>(
                relationshipBuilder.Metadata.DeclaringEntityType.Model.ConventionDispatcher);

            CreateNotNullNavigationConvention().ProcessNavigationAdded(relationshipBuilder, navigation, context);
            return(context.ShouldStopProcessing() ? (Navigation)context.Result : navigation);
        }
            public IConventionModelBuilder OnModelFinalized([NotNull] IConventionModelBuilder modelBuilder)
            {
                _modelBuilderConventionContext.ResetState(modelBuilder);
                foreach (var modelConvention in _conventionSet.ModelFinalizedConventions)
                {
                    // Execute each convention in a separate batch so model validation will get an up-to-date model
                    using (_dispatcher.DelayConventions())
                    {
                        modelConvention.ProcessModelFinalized(modelBuilder, _modelBuilderConventionContext);
                        if (_modelBuilderConventionContext.ShouldStopProcessing())
                        {
                            return(_modelBuilderConventionContext.Result);
                        }
                    }
                }

                return(modelBuilder);
            }
            public override IConventionEntityType OnEntityTypeRemoved(
                IConventionModelBuilder modelBuilder, IConventionEntityType entityType)
            {
                using (_dispatcher.DelayConventions())
                {
                    _entityTypeConventionContext.ResetState(entityType);
                    foreach (var entityTypeConvention in _conventionSet.EntityTypeRemovedConventions)
                    {
                        entityTypeConvention.ProcessEntityTypeRemoved(modelBuilder, entityType, _entityTypeConventionContext);
                        if (_entityTypeConventionContext.ShouldStopProcessing())
                        {
                            return(_entityTypeConventionContext.Result);
                        }
                    }
                }

                return(entityType);
            }
Exemple #11
0
        private void RunConvention(InternalEntityTypeBuilder entityTypeBuilder, EntityType oldBaseType)
        {
            var context = new ConventionContext <IConventionEntityType>(entityTypeBuilder.Metadata.Model.ConventionDispatcher);

            new DiscriminatorConvention(CreateDependencies())
            .ProcessEntityTypeBaseTypeChanged(
                entityTypeBuilder, entityTypeBuilder.Metadata.BaseType, oldBaseType, context);
            Assert.False(context.ShouldStopProcessing());
        }
Exemple #12
0
        private void RunConvention(InternalEntityTypeBuilder entityTypeBuilder, EntityType oldBaseType)
        {
            var logger  = new TestLogger <DbLoggerCategory.Model, TestRelationalLoggingDefinitions>();
            var context = new ConventionContext <IConventionEntityType>(entityTypeBuilder.Metadata.Model.ConventionDispatcher);

            new DiscriminatorConvention(logger)
            .ProcessEntityTypeBaseTypeChanged(
                entityTypeBuilder, entityTypeBuilder.Metadata.BaseType, oldBaseType, context);
            Assert.False(context.ShouldStopProcessing());
        }
Exemple #13
0
        private EntityType RunConvention(EntityType entityType)
        {
            entityType.AddProperty(nameof(Blog.Id), typeof(int), ConfigurationSource.Explicit, ConfigurationSource.Explicit);

            var context = new ConventionContext <IConventionEntityTypeBuilder>(entityType.Model.ConventionDispatcher);

            CreateServicePropertyDiscoveryConvention().ProcessEntityTypeAdded(entityType.Builder, context);

            return(context.ShouldStopProcessing() ? (EntityType)context.Result.Metadata : entityType);
        }
            public override IConventionRelationshipBuilder OnForeignKeyAdded(IConventionRelationshipBuilder relationshipBuilder)
            {
                if (relationshipBuilder.Metadata.DeclaringEntityType.Builder == null ||
                    relationshipBuilder.Metadata.PrincipalEntityType.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _relationshipBuilderConventionContext.ResetState(relationshipBuilder);
                    foreach (var foreignKeyConvention in _conventionSet.ForeignKeyAddedConventions)
                    {
                        if (relationshipBuilder.Metadata.Builder == null)
                        {
                            return(null);
                        }

                        foreignKeyConvention.ProcessForeignKeyAdded(relationshipBuilder, _relationshipBuilderConventionContext);
                        if (_relationshipBuilderConventionContext.ShouldStopProcessing())
                        {
                            return(_relationshipBuilderConventionContext.Result);
                        }
                    }
                }

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

                return(relationshipBuilder);
            }
Exemple #15
0
            public override IConventionSkipNavigation OnSkipNavigationInverseChanged(
                IConventionSkipNavigationBuilder navigationBuilder,
                IConventionSkipNavigation inverse,
                IConventionSkipNavigation oldInverse)
            {
                if (navigationBuilder.Metadata.DeclaringEntityType.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _skipNavigationConventionContext.ResetState(inverse);
                    foreach (var skipNavigationConvention in _conventionSet.SkipNavigationInverseChangedConventions)
                    {
                        if (navigationBuilder.Metadata.Builder == null ||
                            navigationBuilder.Metadata.Inverse != inverse)
                        {
                            Check.DebugAssert(false, "inverse changed");
                            return(null);
                        }

                        skipNavigationConvention.ProcessSkipNavigationInverseChanged(
                            navigationBuilder, inverse, oldInverse, _skipNavigationConventionContext);
                        if (_skipNavigationConventionContext.ShouldStopProcessing())
                        {
                            return(_skipNavigationConventionContext.Result);
                        }
                    }
                }

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

                return(inverse);
            }
            public override IConventionKey OnEntityTypePrimaryKeyChanged(
                IConventionEntityTypeBuilder entityTypeBuilder, IConventionKey newPrimaryKey, IConventionKey previousPrimaryKey)
            {
                if (entityTypeBuilder.Metadata.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _keyConventionContext.ResetState(newPrimaryKey);
                    foreach (var keyConvention in _conventionSet.EntityTypePrimaryKeyChangedConventions)
                    {
                        // Some conventions rely on this running even if the new key has been removed
                        // This will be fixed by reference counting, see #15898
                        //if (newPrimaryKey != null && newPrimaryKey.Builder == null)
                        //{
                        //return null;
                        //}

                        keyConvention.ProcessEntityTypePrimaryKeyChanged(
                            entityTypeBuilder, newPrimaryKey, previousPrimaryKey, _keyConventionContext);
                        if (_keyConventionContext.ShouldStopProcessing())
                        {
                            return(_keyConventionContext.Result);
                        }
                    }
                }

                if (newPrimaryKey != null &&
                    newPrimaryKey.Builder == null)
                {
                    return(null);
                }

                return(newPrimaryKey);
            }
Exemple #17
0
            public override IConventionAnnotation OnModelAnnotationChanged(
                IConventionModelBuilder modelBuilder,
                string name,
                IConventionAnnotation annotation,
                IConventionAnnotation oldAnnotation)
            {
                using (_dispatcher.DelayConventions())
                {
                    _annotationConventionContext.ResetState(annotation);
                    foreach (var modelConvention in _conventionSet.ModelAnnotationChangedConventions)
                    {
                        modelConvention.ProcessModelAnnotationChanged(
                            modelBuilder, name, annotation, oldAnnotation, _annotationConventionContext);

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

                return(annotation);
            }
            public override FieldInfo OnPropertyFieldChanged(
                IConventionPropertyBuilder propertyBuilder, FieldInfo newFieldInfo, FieldInfo oldFieldInfo)
            {
                if (propertyBuilder.Metadata.Builder == null ||
                    propertyBuilder.Metadata.DeclaringEntityType.Builder == null)
                {
                    return(null);
                }

                _fieldInfoConventionContext.ResetState(newFieldInfo);
                foreach (var propertyConvention in _conventionSet.PropertyFieldChangedConventions)
                {
                    propertyConvention.ProcessPropertyFieldChanged(
                        propertyBuilder, newFieldInfo, oldFieldInfo, _fieldInfoConventionContext);
                    if (_fieldInfoConventionContext.ShouldStopProcessing())
                    {
                        return(_fieldInfoConventionContext.Result);
                    }
                }

                return(newFieldInfo);
            }
            public override IConventionIndex OnIndexRemoved(IConventionEntityTypeBuilder entityTypeBuilder, IConventionIndex index)
            {
                if (entityTypeBuilder.Metadata.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _indexConventionContext.ResetState(index);
                    foreach (var indexConvention in _conventionSet.IndexRemovedConventions)
                    {
                        indexConvention.ProcessIndexRemoved(entityTypeBuilder, index, _indexConventionContext);
                        if (_indexConventionContext.ShouldStopProcessing())
                        {
                            return(_indexConventionContext.Result);
                        }
                    }
                }

                return(index);
            }
            public override IConventionForeignKey OnForeignKeyRemoved(
                IConventionEntityTypeBuilder entityTypeBuilder, IConventionForeignKey foreignKey)
            {
                if (entityTypeBuilder.Metadata.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _foreignKeyConventionContext.ResetState(foreignKey);
                    foreach (var foreignKeyConvention in _conventionSet.ForeignKeyRemovedConventions)
                    {
                        foreignKeyConvention.ProcessForeignKeyRemoved(entityTypeBuilder, foreignKey, _foreignKeyConventionContext);
                        if (_foreignKeyConventionContext.ShouldStopProcessing())
                        {
                            return(_foreignKeyConventionContext.Result);
                        }
                    }
                }

                return(foreignKey);
            }
Exemple #21
0
            public override IConventionProperty OnPropertyRemoved(
                IConventionEntityTypeBuilder entityTypeBuilder,
                IConventionProperty property)
            {
                if (entityTypeBuilder.Metadata.Builder == null)
                {
                    return(null);
                }

                using (_dispatcher.DelayConventions())
                {
                    _propertyConventionContext.ResetState(property);
                    foreach (var propertyConvention in _conventionSet.PropertyRemovedConventions)
                    {
                        propertyConvention.ProcessPropertyRemoved(entityTypeBuilder, property, _propertyConventionContext);
                        if (_propertyConventionContext.ShouldStopProcessing())
                        {
                            return(_propertyConventionContext.Result);
                        }
                    }
                }

                return(property);
            }