/// <summary>
        ///     Returns the model from the cache, or creates a model if it is not present in the cache.
        /// </summary>
        /// <param name="context"> The context the model is being produced for. </param>
        /// <param name="conventionSetBuilder"> The convention set to use when creating the model. </param>
        /// <returns> The model to be used. </returns>
        public virtual IModel GetModel(
            DbContext context,
            IConventionSetBuilder conventionSetBuilder)
        {
            var modelBuilder = new ModelBuilder(conventionSetBuilder.CreateConventionSet());

            Dependencies.ModelCustomizer.Customize(modelBuilder, context);
            return(modelBuilder.FinalizeModel());
        }
        protected IModel CreateModel(
            DbContext context,
            IConventionSetBuilder conventionSetBuilder)
        {
            var modelBuilder = new ModelBuilder(conventionSetBuilder.CreateConventionSet());

            _dependencies.ModelCustomizer.Customize(modelBuilder, context);
            return(modelBuilder.Model);
        }
예제 #3
0
        protected override IModel CreateModel(
            DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies)
        {
            var modelBuilder = new ModelBuilder(conventionSetBuilder.CreateConventionSet(), modelDependencies);

            Dependencies.ModelCustomizer.Customize(modelBuilder, context);

            _onModelCreating(modelBuilder, context);

            return(modelBuilder.FinalizeModel());
        }
예제 #4
0
        /// <summary>
        ///     Creates the model. This method is called when the model was not found in the cache.
        /// </summary>
        /// <param name="context"> The context the model is being produced for. </param>
        /// <param name="conventionSetBuilder"> The convention set to use when creating the model. </param>
        /// <returns> The model to be used. </returns>
        protected virtual IModel CreateModel(
            [NotNull] DbContext context,
            [NotNull] IConventionSetBuilder conventionSetBuilder)
        {
            Check.NotNull(context, nameof(context));

            var modelBuilder = new ModelBuilder(conventionSetBuilder.CreateConventionSet());

            Dependencies.ModelCustomizer.Customize(modelBuilder, context);

            return(modelBuilder.FinalizeModel());
        }
예제 #5
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 IModel Process(IModel model)
        {
            if (model == null)
            {
                return(null);
            }

            var version = model.GetProductVersion();

            if (version != null)
            {
                ProcessElement(model, version);
                UpdateSequences(model, version);

                foreach (var entityType in model.GetEntityTypes())
                {
                    ProcessElement(entityType, version);
                    ProcessCollection(entityType.GetProperties(), version);
                    ProcessCollection(entityType.GetKeys(), version);
                    ProcessCollection(entityType.GetIndexes(), version);

                    foreach (var element in entityType.GetForeignKeys())
                    {
                        ProcessElement(element, version);
                        ProcessElement(element.DependentToPrincipal, version);
                        ProcessElement(element.PrincipalToDependent, version);
                    }
                }
            }

            if (model is IConventionModel conventionModel)
            {
                var conventionSet = _conventionSetBuilder.CreateConventionSet();

                var typeMappingConvention = conventionSet.ModelFinalizingConventions.OfType <TypeMappingConvention>().FirstOrDefault();
                if (typeMappingConvention != null)
                {
                    typeMappingConvention.ProcessModelFinalizing(conventionModel.Builder, null);
                }

                var relationalModelConvention =
                    conventionSet.ModelFinalizedConventions.OfType <RelationalModelConvention>().FirstOrDefault();
                if (relationalModelConvention != null)
                {
                    model = relationalModelConvention.ProcessModelFinalized(conventionModel);
                }
            }

            return(model is IMutableModel mutableModel
                ? mutableModel.FinalizeModel()
                : model);
        }
        protected override IModel CreateModel(
            DbContext context,
            IConventionSetBuilder conventionSetBuilder,
            IModelValidator validator,
            DiagnosticsLoggers loggers)
        {
            var conventionSet = conventionSetBuilder.CreateConventionSet();

            conventionSet.ModelBuiltConventions.Add(new ValidatingConvention(validator, loggers));

            var modelBuilder = new ModelBuilder(conventionSet);

            Dependencies.ModelCustomizer.Customize(modelBuilder, context);

            _onModelCreating(modelBuilder, context);

            return(modelBuilder.FinalizeModel());
        }
예제 #7
0
        /// <summary>
        ///     Creates the model. This method is called when the model was not found in the cache.
        /// </summary>
        /// <param name="context"> The context the model is being produced for. </param>
        /// <param name="conventionSetBuilder"> The convention set to use when creating the model. </param>
        /// <param name="validator"> The validator to verify the model can be successfully used with the context. </param>
        /// <param name="loggers"> The loggers to use. </param>
        /// <returns> The model to be used. </returns>
        protected virtual IModel CreateModel(
            [NotNull] DbContext context,
            [NotNull] IConventionSetBuilder conventionSetBuilder,
            [NotNull] IModelValidator validator,
            DiagnosticsLoggers loggers)
        {
            Check.NotNull(context, nameof(context));
            Check.NotNull(validator, nameof(validator));
            Check.NotNull(loggers, nameof(loggers));

            var conventionSet = conventionSetBuilder.CreateConventionSet();

            conventionSet.ModelBuiltConventions.Add(new ValidatingConvention(validator, loggers));

            var modelBuilder = new ModelBuilder(conventionSet);

            Dependencies.ModelCustomizer.Customize(modelBuilder, context);

            return(modelBuilder.FinalizeModel());
        }
예제 #8
0
        private IModel FinalizeModel(IModel model)
        {
            if (model is IConventionModel conventionModel)
            {
                var conventionSet = _conventionSetBuilder.CreateConventionSet();

                var typeMappingConvention = conventionSet.ModelFinalizingConventions.OfType <TypeMappingConvention>().FirstOrDefault();
                if (typeMappingConvention != null)
                {
                    typeMappingConvention.ProcessModelFinalizing(conventionModel.Builder, null);
                }

                var relationalModelConvention = conventionSet.ModelFinalizedConventions.OfType <RelationalModelConvention>().FirstOrDefault();
                if (relationalModelConvention != null)
                {
                    relationalModelConvention.ProcessModelFinalized(conventionModel);
                }

                return(conventionModel.FinalizeModel());
            }

            return(model);
        }