Example #1
0
        private DbModel Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
        {
            DebugCheck.NotNull(providerManifest);
            DebugCheck.NotNull(providerInfo);

            var model = new EdmModel().Initialize(_modelBuilderVersion.GetEdmVersion());

            model.SetProviderInfo(providerInfo);

            _conventionsConfiguration.ApplyModelConfiguration(_modelConfiguration);

            _modelConfiguration.NormalizeConfigurations();

            MapTypes(model);

            _modelConfiguration.Configure(model);
            _conventionsConfiguration.ApplyModel(model);

            model.ValidateCsdl();

            var databaseMapping = model.GenerateDatabaseMapping(providerManifest);

            //Running the PluralizingTableNameConvention first so that the new table name is available for configuration
            _conventionsConfiguration.ApplyPluralizingTableNameConvention(databaseMapping.Database);
            _modelConfiguration.Configure(databaseMapping, providerManifest);
            _conventionsConfiguration.ApplyDatabase(databaseMapping.Database);
            _conventionsConfiguration.ApplyMapping(databaseMapping);

            databaseMapping.Database.SetProviderInfo(providerInfo);

            return(new DbModel(databaseMapping, Clone()));
        }
        public void ApplyModelConfiguration_should_run_type_model_configuration_conventions()
        {
            var mockConvention           = new Mock <IConfigurationConvention <Type, ModelConfiguration> >();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });
            var modelConfiguration       = new ModelConfiguration();

            conventionsConfiguration.ApplyModelConfiguration(typeof(object), modelConfiguration);

            mockConvention.Verify(c => c.Apply(typeof(object), It.IsAny <Func <ModelConfiguration> >()), Times.AtMostOnce());
        }
        public void ApplyModelConfiguration_should_run_model_configuration_conventions()
        {
            var mockConvention           = new Mock <IConfigurationConvention>();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });
            var modelConfiguration       = new ModelConfiguration();

            conventionsConfiguration.ApplyModelConfiguration(modelConfiguration);

            mockConvention.Verify(c => c.Apply(modelConfiguration), Times.Once());
        }
Example #4
0
        private DbModel Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
        {
            DebugCheck.NotNull(providerManifest);
            DebugCheck.NotNull(providerInfo);

            var schemaVersion     = _modelBuilderVersion.GetEdmVersion();
            var modelBuilderClone = Clone();

            var model = new DbModel(
                new DbDatabaseMapping()
            {
                Model    = EdmModel.CreateConceptualModel(schemaVersion),
                Database = EdmModel.CreateStoreModel(providerInfo, providerManifest, schemaVersion)
            },
                modelBuilderClone);

            model.ConceptualModel.Container.AddAnnotation(XmlConstants.UseClrTypesAnnotationWithPrefix, "true");

            _conventionsConfiguration.ApplyModelConfiguration(_modelConfiguration);

            _modelConfiguration.NormalizeConfigurations();

            MapTypes(model.ConceptualModel);

            _modelConfiguration.Configure(model.ConceptualModel);

            _conventionsConfiguration.ApplyConceptualModel(model);

            model.ConceptualModel.Validate();

            model = new DbModel(
                model.ConceptualModel.GenerateDatabaseMapping(providerInfo, providerManifest),
                modelBuilderClone);

            // Run the PluralizingTableNameConvention first so that the new table name is available for configuration
            _conventionsConfiguration.ApplyPluralizingTableNameConvention(model);

            _modelConfiguration.Configure(model.DatabaseMapping, providerManifest);

            _conventionsConfiguration.ApplyStoreModel(model);

            _conventionsConfiguration.ApplyMapping(model.DatabaseMapping);

            model.StoreModel.Validate();

            return(model);
        }
Example #5
0
 internal virtual void ApplyModelConfiguration(ModelConfiguration modelConfiguration)
 {
     _conventionsConfiguration.ApplyModelConfiguration(modelConfiguration);
 }
        public void ApplyModelConfiguration_should_run_type_model_configuration_conventions()
        {
            var mockConvention = new Mock<IConfigurationConvention<Type, ModelConfiguration>>();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });
            var modelConfiguration = new ModelConfiguration();

            conventionsConfiguration.ApplyModelConfiguration(typeof(object), modelConfiguration);

            mockConvention.Verify(c => c.Apply(typeof(object), It.IsAny<Func<ModelConfiguration>>()), Times.AtMostOnce());
        }
        public void ApplyModelConfiguration_should_run_model_configuration_conventions()
        {
            var mockConvention = new Mock<IConfigurationConvention>();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });
            var modelConfiguration = new ModelConfiguration();

            conventionsConfiguration.ApplyModelConfiguration(modelConfiguration);

            mockConvention.Verify(c => c.Apply(modelConfiguration), Times.Once());
        }