public void Map_should_create_association_sets_for_associations()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel().Initialize();
            var entityType = new EntityType
                                 {
                                     Name = "Source"
                                 };
            model.AddEntitySet("Source", entityType);

            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(
                    new MockPropertyInfo(new MockType("Target"), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, model.Containers.Single().AssociationSets.Count);

            var associationSet = model.Containers.Single().AssociationSets.Single();

            Assert.NotNull(associationSet);
            Assert.NotNull(associationSet.ElementType);
            Assert.Equal("Source_Nav", associationSet.Name);
        }
Пример #2
0
 protected override void ApplyCore(
     Type memberInfo,
     Func <ComplexTypeConfiguration> configuration,
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration)
 {
     this._entityConfigurationAction(new ConventionTypeConfiguration <T>(memberInfo, configuration, modelConfiguration));
 }
Пример #3
0
 internal virtual void ApplyPropertyConfiguration(
     PropertyInfo propertyInfo,
     Func <PropertyConfiguration> propertyConfiguration,
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration)
 {
     this._conventionsConfiguration.ApplyPropertyConfiguration(propertyInfo, propertyConfiguration, modelConfiguration);
 }
Пример #4
0
 protected override void InvokeAction(
     Type memberInfo,
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration,
     TValue value)
 {
     this._entityConfigurationAction(new ConventionTypeConfiguration <T>(memberInfo, modelConfiguration), value);
 }
Пример #5
0
 protected override void ApplyCore(
     PropertyInfo memberInfo,
     Func <System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration> configuration,
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration)
 {
     this._propertyConfigurationAction(new ConventionPrimitivePropertyConfiguration(memberInfo, configuration));
 }
        public void Apply_ignores_constraint_when_inverse_constraint_already_specified()
        {
            var mockPropertyInfo = typeof(AType4).GetInstanceProperty("B");
            var mockInversePropertyInfo = typeof(BType4).GetInstanceProperty("A");

            var modelConfiguration = new ModelConfiguration();
            var navigationPropertyConfiguration
                = modelConfiguration.Entity(typeof(AType4)).Navigation(mockPropertyInfo);

            var inverseNavigationPropertyConfiguration
                = modelConfiguration.Entity(typeof(BType4)).Navigation(mockInversePropertyInfo);

            navigationPropertyConfiguration.InverseNavigationProperty = mockInversePropertyInfo;

            inverseNavigationPropertyConfiguration.Constraint
                = new ForeignKeyConstraintConfiguration(new[] { typeof(BType4).GetInstanceProperty("AId1") });

            new ForeignKeyPrimitivePropertyAttributeConvention()
                .Apply(
                    typeof(BType4).GetInstanceProperty("AId1"),
                    new ConventionTypeConfiguration(typeof(BType4), () => modelConfiguration.Entity(typeof(BType4)), modelConfiguration),
                    new ForeignKeyAttribute("A"));

            Assert.Null(navigationPropertyConfiguration.Constraint);
        }
Пример #7
0
        public void Apply_adds_fk_column_when_nav_prop_is_valid()
        {
            var mockTypeA = new MockType("A");
            var mockTypeB = new MockType("B").Property<int>("AId").Property(mockTypeA, "A");
            var mockPropertyInfo = mockTypeB.GetProperty("AId");
            var mockNavigationPropertyInfo = mockTypeB.GetProperty("A");

            var modelConfiguration = new ModelConfiguration();

            new ForeignKeyPrimitivePropertyAttributeConvention()
                .Apply(
                    mockPropertyInfo,
                    new ConventionTypeConfiguration(mockTypeB, () => modelConfiguration.Entity(mockTypeB), modelConfiguration),
                    new ForeignKeyAttribute("A"));

            var navigationPropertyConfiguration
                = modelConfiguration.Entity(mockTypeB).Navigation(mockNavigationPropertyInfo);

            Assert.NotNull(navigationPropertyConfiguration.Constraint);

            var foreignKeyConstraint = (ForeignKeyConstraintConfiguration)navigationPropertyConfiguration.Constraint;

            Assert.Equal(new[] { mockTypeB.GetProperty("AId") }, foreignKeyConstraint.ToProperties);
            Assert.Null(navigationPropertyConfiguration.InverseNavigationProperty);
        }
Пример #8
0
        protected override void ApplyCore(Type memberInfo, ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(memberInfo);
            DebugCheck.NotNull(modelConfiguration);

            _entityConfigurationAction(new ConventionTypeConfiguration(memberInfo, modelConfiguration));
        }
        public void Configure_should_uniquify_unconfigured_assocation_function_names()
        {
            var typeA = new MockType("A");
            var typeB = new MockType("B").Property(typeA.AsCollection(), "As");
            var mockPropertyInfo = typeB.GetProperty("As");
            typeA.Property(typeB.AsCollection(), "Bs");

            var modelConfiguration = new ModelConfiguration();

            var navigationPropertyConfiguration
                = modelConfiguration.Entity(typeB).Navigation(mockPropertyInfo);

            navigationPropertyConfiguration.ModificationFunctionsConfiguration
                = new ModificationFunctionsConfiguration();

            var modificationFunctionConfiguration = new ModificationFunctionConfiguration();
            modificationFunctionConfiguration.HasName("M2M_Delete");

            navigationPropertyConfiguration.ModificationFunctionsConfiguration
                .Insert(modificationFunctionConfiguration);

            var model = new EdmModel(DataSpace.CSpace);

            var entityA = model.AddEntityType("A");
            entityA.Annotations.SetClrType(typeA);
            entityA.SetConfiguration(modelConfiguration.Entity(typeA));

            var entityB = model.AddEntityType("B");
            entityB.Annotations.SetClrType(typeB);
            entityB.SetConfiguration(modelConfiguration.Entity(typeB));

            model.AddEntitySet("AS", entityA);
            model.AddEntitySet("BS", entityB);

            var associationType
                = model.AddAssociationType(
                    "M2M",
                    entityA,
                    RelationshipMultiplicity.Many,
                    entityB,
                    RelationshipMultiplicity.Many);

            associationType.SetConfiguration(navigationPropertyConfiguration);

            var navigationProperty
                = entityB.AddNavigationProperty("As", associationType);

            navigationProperty.SetClrPropertyInfo(mockPropertyInfo);

            model.AddAssociationSet("M2MSet", associationType);

            var databaseMapping
                = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderManifest)
                    .Generate(model);

            modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);

            Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete"));
            Assert.True(databaseMapping.Database.Functions.Any(f => f.Name == "M2M_Delete1"));
        }
        public void Apply_ignores_constraint_when_inverse_constraint_already_specified()
        {
            var mockTypeA = new MockType("A");
            var mockTypeB = new MockType("B").Property(mockTypeA, "A").Property<int>("AId1").Property<int>("AId2");
            mockTypeA.Property(mockTypeB, "B");

            var mockPropertyInfo = mockTypeA.GetProperty("B");
            var mockInversePropertyInfo = mockTypeB.GetProperty("A");

            var modelConfiguration = new ModelConfiguration();
            var navigationPropertyConfiguration
                = modelConfiguration.Entity(mockTypeA).Navigation(mockPropertyInfo);

            var inverseNavigationPropertyConfiguration
                = modelConfiguration.Entity(mockTypeB).Navigation(mockInversePropertyInfo);

            navigationPropertyConfiguration.InverseNavigationProperty = mockInversePropertyInfo;

            inverseNavigationPropertyConfiguration.Constraint
                = new ForeignKeyConstraintConfiguration(new[] { mockTypeB.GetProperty("AId1") });

            new ForeignKeyPrimitivePropertyAttributeConvention.ForeignKeyAttributeConventionImpl()
                .Apply(mockPropertyInfo, modelConfiguration, new ForeignKeyAttribute("AId2"));

            Assert.Null(navigationPropertyConfiguration.Constraint);
        }
        public static void ConfigureEdmMetadata(ModelConfiguration modelConfiguration)
        {
            //Contract.Requires(modelConfiguration != null);

#pragma warning disable 612,618
            modelConfiguration.Entity(typeof(EdmMetadata)).ToTable(TableName);
#pragma warning restore 612,618
        }
Пример #12
0
 protected override void InvokeAction(
     Type memberInfo,
     Func <ComplexTypeConfiguration> configuration,
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration,
     T value)
 {
     this._entityConfigurationAction(new ConventionTypeConfiguration(memberInfo, configuration, modelConfiguration), value);
 }
Пример #13
0
 internal DbModelBuilder(
     ModelConfiguration.Configuration.ModelConfiguration modelConfiguration,
     DbModelBuilderVersion modelBuilderVersion = DbModelBuilderVersion.Latest)
     : this(
         modelConfiguration, new ConventionsConfiguration(SelectConventionSet(modelBuilderVersion)),
         modelBuilderVersion)
 {
 }
 internal ConventionTypeConfiguration(
     Type type,
     Func<EntityTypeConfiguration> entityTypeConfiguration,
     ModelConfiguration modelConfiguration)
     : this(type, entityTypeConfiguration, null, modelConfiguration)
 {
     DebugCheck.NotNull(entityTypeConfiguration);
 }
Пример #15
0
 internal virtual void ApplyPropertyTypeConfiguration <TStructuralTypeConfiguration>(
     PropertyInfo propertyInfo,
     Func <TStructuralTypeConfiguration> structuralTypeConfiguration,
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration)
     where TStructuralTypeConfiguration : StructuralTypeConfiguration
 {
     this._conventionsConfiguration.ApplyPropertyTypeConfiguration <TStructuralTypeConfiguration>(propertyInfo, structuralTypeConfiguration, modelConfiguration);
 }
Пример #16
0
        private DbModelBuilder(DbModelBuilder source)
        {
            DebugCheck.NotNull(source);

            _modelConfiguration       = source._modelConfiguration.Clone();
            _conventionsConfiguration = source._conventionsConfiguration.Clone();
            _modelBuilderVersion      = source._modelBuilderVersion;
        }
 internal ConventionTypeConfiguration(
     Type type,
     Func<ComplexTypeConfiguration> complexTypeConfiguration,
     ModelConfiguration modelConfiguration)
     : this(type, null, complexTypeConfiguration, modelConfiguration)
 {
     DebugCheck.NotNull(complexTypeConfiguration);
 }
Пример #18
0
        public static void ConfigureEdmMetadata(ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(modelConfiguration);

#pragma warning disable 612,618
            modelConfiguration.Entity(typeof(EdmMetadata)).ToTable(TableName);
#pragma warning restore 612,618
        }
Пример #19
0
 internal virtual void ApplyTypeConfiguration <TStructuralTypeConfiguration>(
     Type type,
     Func <TStructuralTypeConfiguration> structuralTypeConfiguration,
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration)
     where TStructuralTypeConfiguration : StructuralTypeConfiguration
 {
     this._conventionsConfiguration.ApplyTypeConfiguration <TStructuralTypeConfiguration>(type, structuralTypeConfiguration, modelConfiguration);
 }
        public void Add_complex_type_configuration_should_add_to_model_configuration()
        {
            var modelConfiguration = new ModelConfiguration();
            var complexTypeConfiguration = new ComplexTypeConfiguration<object>();

            new ConfigurationRegistrar(modelConfiguration).Add(complexTypeConfiguration);

            Assert.Same(complexTypeConfiguration.Configuration, modelConfiguration.ComplexType(typeof(object)));
        }
Пример #21
0
        protected override void ApplyCore(
            PropertyInfo memberInfo, Func<PrimitivePropertyConfiguration> configuration, ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(memberInfo);
            DebugCheck.NotNull(configuration);
            DebugCheck.NotNull(modelConfiguration);

            _propertyConfigurationAction(new ConventionPrimitivePropertyConfiguration(memberInfo, configuration));
        }
Пример #22
0
        private ModelConfiguration(ModelConfiguration source)
        {
            source._entityConfigurations.Each(c => _entityConfigurations.Add(c.Key, c.Value.Clone()));
            source._complexTypeConfigurations.Each(c => _complexTypeConfigurations.Add(c.Key, c.Value.Clone()));

            _ignoredTypes.AddRange(source._ignoredTypes);

            DefaultSchema = source.DefaultSchema;
        }
        public void Apply_should_set_model_namespace()
        {
            var convention = new ModelNamespaceConvention("Foo");
            var modelConfiguration = new ModelConfiguration();

            convention.Apply(modelConfiguration);

            Assert.Equal("Foo", modelConfiguration.ModelNamespace);
        }
        public void Configure_should_uniquify_unconfigured_association_function_names()
        {
            var mockPropertyInfo = typeof(BType1).GetDeclaredProperty("As");

            var modelConfiguration = new ModelConfiguration();

            var navigationPropertyConfiguration
                = modelConfiguration.Entity(typeof(BType1)).Navigation(mockPropertyInfo);

            navigationPropertyConfiguration.ModificationStoredProceduresConfiguration
                = new ModificationStoredProceduresConfiguration();

            var modificationFunctionConfiguration = new ModificationStoredProcedureConfiguration();
            modificationFunctionConfiguration.HasName("AB_Delete");

            navigationPropertyConfiguration.ModificationStoredProceduresConfiguration
                .Insert(modificationFunctionConfiguration);

            var model = new EdmModel(DataSpace.CSpace);

            var entityA = model.AddEntityType("A");
            entityA.GetMetadataProperties().SetClrType(typeof(AType1));
            entityA.SetConfiguration(modelConfiguration.Entity(typeof(AType1)));

            var entityB = model.AddEntityType("B");
            entityB.GetMetadataProperties().SetClrType(typeof(BType1));
            entityB.SetConfiguration(modelConfiguration.Entity(typeof(BType1)));

            model.AddEntitySet("AS", entityA);
            model.AddEntitySet("BS", entityB);

            var associationType
                = model.AddAssociationType(
                    "M2M",
                    entityA,
                    RelationshipMultiplicity.Many,
                    entityB,
                    RelationshipMultiplicity.Many);

            associationType.SetConfiguration(navigationPropertyConfiguration);

            var navigationProperty
                = entityB.AddNavigationProperty("As", associationType);

            navigationProperty.SetClrPropertyInfo(mockPropertyInfo);

            model.AddAssociationSet("M2MSet", associationType);

            var databaseMapping
                = new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest)
                    .Generate(model);

            modelConfiguration.Configure(databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);

            Assert.True(databaseMapping.Database.Functions.Any(f => f.StoreFunctionNameAttribute == "AB_Delete"));
            Assert.True(databaseMapping.Database.Functions.Any(f => f.StoreFunctionNameAttribute == "AB_Delete1"));
        }
        public void Add_entity_configuration_should_add_to_model_configuration()
        {
            var modelConfiguration = new ModelConfiguration();
            var entityConfiguration = new EntityTypeConfiguration<object>();

            new ConfigurationRegistrar(modelConfiguration).Add(entityConfiguration);

            Assert.Same(entityConfiguration.Configuration, modelConfiguration.Entity(typeof(object)));
        }
        public void IsComplexType_configures()
        {
            var type = typeof(LocalEntityType);
            var innerConfig = new ModelConfiguration();
            var config = new ConventionTypeConfiguration<LocalEntityType>(type, innerConfig);

            config.IsComplexType();

            Assert.True(innerConfig.IsComplexType(typeof(LocalEntityType)));
        }
        public void Get_configured_types_should_return_types()
        {
            var modelConfiguration = new ModelConfiguration();
            var configurationRegistrar
                = new ConfigurationRegistrar(modelConfiguration)
                    .Add(new ComplexTypeConfiguration<object>())
                    .Add(new EntityTypeConfiguration<string>());

            Assert.Equal(2, configurationRegistrar.GetConfiguredTypes().Count());
        }
        public void Apply_should_inline_type()
        {
            var mockType = new MockType();
            var modelConfiguration = new ModelConfiguration();

            new ComplexTypeAttributeConvention.ComplexTypeAttributeConventionImpl()
                .Apply(mockType, modelConfiguration, new ComplexTypeAttribute());

            Assert.True(modelConfiguration.IsComplexType(mockType));
        }
        public void Apply_should_ignore_type()
        {
            var mockType = new MockType();
            var modelConfiguration = new ModelConfiguration();

            new NotMappedTypeAttributeConvention.NotMappedTypeAttributeConventionImpl()
                .Apply(mockType, modelConfiguration, new NotMappedAttribute());

            Assert.True(modelConfiguration.IsIgnoredType(mockType));
        }
Пример #30
0
 private DbModelBuilder(
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration,
     ConventionsConfiguration conventionsConfiguration,
     DbModelBuilderVersion modelBuilderVersion = DbModelBuilderVersion.Latest)
 {
     if (!Enum.IsDefined(typeof(DbModelBuilderVersion), (object)modelBuilderVersion))
     {
         throw new ArgumentOutOfRangeException(nameof(modelBuilderVersion));
     }
     this._modelConfiguration       = modelConfiguration;
     this._conventionsConfiguration = conventionsConfiguration;
     this._modelBuilderVersion      = modelBuilderVersion;
 }
Пример #31
0
 public MappingContext(
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration,
     ConventionsConfiguration conventionsConfiguration,
     EdmModel model,
     DbModelBuilderVersion modelBuilderVersion = DbModelBuilderVersion.Latest,
     AttributeProvider attributeProvider       = null)
 {
     this._modelConfiguration       = modelConfiguration;
     this._conventionsConfiguration = conventionsConfiguration;
     this._model = model;
     this._modelBuilderVersion = modelBuilderVersion;
     this._attributeProvider   = attributeProvider ?? new AttributeProvider();
 }
Пример #32
0
        protected override void ApplyCore(
            PropertyInfo memberInfo,
            Func <System.Data.Entity.ModelConfiguration.Configuration.Properties.Primitive.PrimitivePropertyConfiguration> configuration,
            System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration)
        {
            T obj = this._capturingPredicate(memberInfo);

            if ((object)obj == null)
            {
                return;
            }
            this._propertyConfigurationAction(new ConventionPrimitivePropertyConfiguration(memberInfo, configuration), obj);
        }
        public void Map_should_not_detect_arrays_as_collection_associations()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel().Initialize();
            var entityType = new EdmEntityType();
            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(typeof(NavigationPropertyMapperTests[]), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(0, model.Namespaces.Single().AssociationTypes.Count);
        }
Пример #34
0
        public MappingContext(
            ModelConfiguration modelConfiguration,
            ConventionsConfiguration conventionsConfiguration,
            EdmModel model)
        {
            //Contract.Requires(modelConfiguration != null);
            //Contract.Requires(conventionsConfiguration != null);
            //Contract.Requires(model != null);

            _modelConfiguration = modelConfiguration;
            _conventionsConfiguration = conventionsConfiguration;
            _model = model;
            _attributeProvider = new AttributeProvider();
        }
        private ConventionTypeConfiguration(
            Type type,
            Func<EntityTypeConfiguration> entityTypeConfiguration,
            Func<ComplexTypeConfiguration> complexTypeConfiguration,
            ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(type);
            DebugCheck.NotNull(modelConfiguration);

            _type = type;
            _entityTypeConfiguration = entityTypeConfiguration;
            _complexTypeConfiguration = complexTypeConfiguration;
            _modelConfiguration = modelConfiguration;
        }
        public void AddFromAssembly_should_add_all_configuration_to_model_configuration()
        {
            var modelConfiguration = new ModelConfiguration();

            new ConfigurationRegistrar(modelConfiguration).AddFromAssembly(CreateDynamicAssemblyWithStructuralTypeConfigurations());

            Assert.Equal(3, modelConfiguration.ComplexTypes.Count());
            Assert.Equal(3, modelConfiguration.Entities.Count());
            Assert.Equal(1, modelConfiguration.ConfiguredTypes.Count(t => t.Name == "Entity1"));
            Assert.Equal(1, modelConfiguration.ConfiguredTypes.Count(t => t.Name == "Complex1"));
            Assert.Equal(1, modelConfiguration.ConfiguredTypes.Count(t => t.Name == "Entity2"));
            Assert.Equal(1, modelConfiguration.ConfiguredTypes.Count(t => t.Name == "Complex2"));
            Assert.Equal(1, modelConfiguration.ConfiguredTypes.Count(t => t.Name == "Entity3"));
            Assert.Equal(1, modelConfiguration.ConfiguredTypes.Count(t => t.Name == "Complex3"));
        }
        public void Apply_finds_inverse_when_optional_to_optional()
        {
            var propertyInfo = typeof(BType3).GetInstanceProperty("A");
            var modelConfiguration = new ModelConfiguration();

            new InversePropertyAttributeConvention()
                .Apply(
                    propertyInfo,
                    new ConventionTypeConfiguration(typeof(BType3), () => modelConfiguration.Entity(typeof(BType3)), modelConfiguration),
                    new InversePropertyAttribute("B"));

            var navigationPropertyConfiguration
                = modelConfiguration.Entity(typeof(BType3)).Navigation(propertyInfo);

            Assert.Same(typeof(AType3).GetDeclaredProperty("B"), navigationPropertyConfiguration.InverseNavigationProperty);
        }
        public void Apply_finds_inverse_when_many_to_many()
        {
            var mockTypeA = new MockType("A");
            var mockTypeB = new MockType("B").Property(mockTypeA.AsCollection(), "As");
            var mockPropertyInfo = mockTypeB.GetProperty("As");
            mockTypeA.Property(mockTypeB.AsCollection(), "Bs");
            var modelConfiguration = new ModelConfiguration();

            new InversePropertyAttributeConvention()
                .Apply(mockPropertyInfo, modelConfiguration, new InversePropertyAttribute("Bs"));

            var navigationPropertyConfiguration
                = modelConfiguration.Entity(mockTypeB).Navigation(mockPropertyInfo);

            Assert.Same(mockTypeA.GetProperty("Bs"), navigationPropertyConfiguration.InverseNavigationProperty);
        }
Пример #39
0
        private DbModelBuilder(
            ModelConfiguration.Configuration.ModelConfiguration modelConfiguration,
            ConventionsConfiguration conventionsConfiguration,
            DbModelBuilderVersion modelBuilderVersion = DbModelBuilderVersion.Latest)
        {
            DebugCheck.NotNull(modelConfiguration);
            DebugCheck.NotNull(conventionsConfiguration);
            if (!(Enum.IsDefined(typeof(DbModelBuilderVersion), modelBuilderVersion)))
            {
                throw new ArgumentOutOfRangeException("modelBuilderVersion");
            }

            _modelConfiguration       = modelConfiguration;
            _conventionsConfiguration = conventionsConfiguration;
            _modelBuilderVersion      = modelBuilderVersion;
        }
        public virtual void AddConfigurationTypesToModel(IEnumerable<Type> types, ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(types);
            DebugCheck.NotNull(modelConfiguration);

            foreach (var type in types)
            {
                if (_filter.IsEntityTypeConfiguration(type))
                {
                    modelConfiguration.Add(_activator.Activate<EntityTypeConfiguration>(type));
                }
                else if (_filter.IsComplexTypeConfiguration(type))
                {
                    modelConfiguration.Add(_activator.Activate<ComplexTypeConfiguration>(type));
                }
            }
        }
Пример #41
0
        public MappingContext(
            ModelConfiguration modelConfiguration,
            ConventionsConfiguration conventionsConfiguration,
            EdmModel model,
            DbModelBuilderVersion modelBuilderVersion = DbModelBuilderVersion.Latest,
            AttributeProvider attributeProvider = null)
        {
            DebugCheck.NotNull(modelConfiguration);
            DebugCheck.NotNull(conventionsConfiguration);
            DebugCheck.NotNull(model);

            _modelConfiguration = modelConfiguration;
            _conventionsConfiguration = conventionsConfiguration;
            _model = model;
            _modelBuilderVersion = modelBuilderVersion;
            _attributeProvider = attributeProvider ?? new AttributeProvider();
        }
        public void Map_should_detect_collection_associations_and_set_correct_end_kinds()
        {
            var modelConfiguration = new ModelConfiguration();
            var model = new EdmModel().Initialize();
            var entityType = new EdmEntityType();
            var mappingContext = new MappingContext(modelConfiguration, new ConventionsConfiguration(), model);

            new NavigationPropertyMapper(new TypeMapper(mappingContext))
                .Map(new MockPropertyInfo(typeof(List<NavigationPropertyMapperTests>), "Nav"), entityType,
                    () => new EntityTypeConfiguration(typeof(object)));

            Assert.Equal(1, model.Namespaces.Single().AssociationTypes.Count);

            var associationType = model.Namespaces.Single().AssociationTypes.Single();

            Assert.Equal(EdmAssociationEndKind.Optional, associationType.SourceEnd.EndKind);
            Assert.Equal(EdmAssociationEndKind.Many, associationType.TargetEnd.EndKind);
        }
        public void AddConfigurationTypesToModel_adds_entitytypeconfigurations_into_model()
        {
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(Random));
            
            var filter = new Mock<ConfigurationTypeFilter>();
            filter.Setup(f => f.IsEntityTypeConfiguration(It.IsAny<Type>())).Returns(true);

            var activator = new Mock<ConfigurationTypeActivator>();
            activator.Setup(a => a.Activate<EntityTypeConfiguration>(It.IsAny<Type>()))
                     .Returns(entityTypeConfiguration);

            var finder = new ConfigurationTypesFinder(activator.Object, filter.Object);
            
            var modelConfiguration = new ModelConfiguration();
            finder.AddConfigurationTypesToModel(new[] { typeof(Object) }, modelConfiguration);

            Assert.Same(entityTypeConfiguration, modelConfiguration.Entity(typeof(Random)));
        }
        public void AddConfigurationTypesToModel_adds_entitytypeconfigurations_into_model()
        {
            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(Random));

            var filter = new Mock <ConfigurationTypeFilter>();

            filter.Setup(f => f.IsEntityTypeConfiguration(It.IsAny <Type>())).Returns(true);

            var activator = new Mock <ConfigurationTypeActivator>();

            activator.Setup(a => a.Activate <EntityTypeConfiguration>(It.IsAny <Type>()))
            .Returns(entityTypeConfiguration);

            var finder = new ConfigurationTypesFinder(activator.Object, filter.Object);

            var modelConfiguration = new ModelConfiguration();

            finder.AddConfigurationTypesToModel(new[] { typeof(Object) }, modelConfiguration);

            Assert.Same(entityTypeConfiguration, modelConfiguration.Entity(typeof(Random)));
        }
        internal virtual void ApplyModelConfiguration(ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(modelConfiguration);

            // PERF: this code is part of a critical path, consider its performance when refactoring
            for (var i = _configurationConventions.Count - 1; i >= 0; --i)
            {
                var convention = _configurationConventions[i];
                var configurationConvention
                    = convention as IConfigurationConvention;

                configurationConvention?.Apply(modelConfiguration);

                var lightweightConfigurationConvention
                    = convention as Convention;

                if (lightweightConfigurationConvention != null)
                {
                    lightweightConfigurationConvention.ApplyModelConfiguration(modelConfiguration);
                }
            }
        }
        internal virtual void ApplyPropertyTypeConfiguration <TStructuralTypeConfiguration>(
            PropertyInfo propertyInfo,
            Func <TStructuralTypeConfiguration> structuralTypeConfiguration,
            ModelConfiguration modelConfiguration)
            where TStructuralTypeConfiguration : StructuralTypeConfiguration
        {
            DebugCheck.NotNull(propertyInfo);
            DebugCheck.NotNull(structuralTypeConfiguration);

            // PERF: this code is part of a critical path, consider its performance when refactoring
            for (var i = _configurationConventions.Count - 1; i >= 0; --i)
            {
                var convention = _configurationConventions[i];
                var propertyTypeConfigurationConvention
                    = convention as IConfigurationConvention <PropertyInfo, TStructuralTypeConfiguration>;

                if (propertyTypeConfigurationConvention != null)
                {
                    propertyTypeConfigurationConvention.Apply(propertyInfo, structuralTypeConfiguration, modelConfiguration);
                }

                var structuralTypeConfigurationConvention
                    = convention as IConfigurationConvention <PropertyInfo, StructuralTypeConfiguration>;

                if (structuralTypeConfigurationConvention != null)
                {
                    structuralTypeConfigurationConvention.Apply(propertyInfo, structuralTypeConfiguration, modelConfiguration);
                }

                var lightweightConfigurationConvention
                    = convention as Convention;

                if (lightweightConfigurationConvention != null)
                {
                    lightweightConfigurationConvention.ApplyPropertyTypeConfiguration(
                        propertyInfo, structuralTypeConfiguration, modelConfiguration);
                }
            }
        }
Пример #47
0
        internal virtual void ApplyModelConfiguration(ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(modelConfiguration);

            foreach (var convention in ((IList <IConvention>)_configurationConventions).Reverse())
            {
                var configurationConvention
                    = convention as IConfigurationConvention;

                if (configurationConvention != null)
                {
                    configurationConvention.Apply(modelConfiguration);
                }

                var lightweightConfigurationConvention
                    = convention as Convention;

                if (lightweightConfigurationConvention != null)
                {
                    lightweightConfigurationConvention.ApplyModelConfiguration(modelConfiguration);
                }
            }
        }
Пример #48
0
        internal virtual void ApplyPropertyTypeConfiguration <TStructuralTypeConfiguration>(
            PropertyInfo propertyInfo,
            Func <TStructuralTypeConfiguration> structuralTypeConfiguration,
            ModelConfiguration modelConfiguration)
            where TStructuralTypeConfiguration : StructuralTypeConfiguration
        {
            DebugCheck.NotNull(propertyInfo);
            DebugCheck.NotNull(structuralTypeConfiguration);

            foreach (var convention in ((IList <IConvention>)_configurationConventions).Reverse())
            {
                var propertyTypeConfigurationConvention
                    = convention as IConfigurationConvention <PropertyInfo, TStructuralTypeConfiguration>;

                if (propertyTypeConfigurationConvention != null)
                {
                    propertyTypeConfigurationConvention.Apply(propertyInfo, structuralTypeConfiguration, modelConfiguration);
                }

                var structuralTypeConfigurationConvention
                    = convention as IConfigurationConvention <PropertyInfo, StructuralTypeConfiguration>;

                if (structuralTypeConfigurationConvention != null)
                {
                    structuralTypeConfigurationConvention.Apply(propertyInfo, structuralTypeConfiguration, modelConfiguration);
                }

                var lightweightConfigurationConvention
                    = convention as Convention;

                if (lightweightConfigurationConvention != null)
                {
                    lightweightConfigurationConvention.ApplyPropertyTypeConfiguration(
                        propertyInfo, structuralTypeConfiguration, modelConfiguration);
                }
            }
        }
        internal virtual void ApplyTypeConfiguration <TStructuralTypeConfiguration>(
            Type type,
            Func <TStructuralTypeConfiguration> structuralTypeConfiguration,
            ModelConfiguration modelConfiguration)
            where TStructuralTypeConfiguration : StructuralTypeConfiguration
        {
            DebugCheck.NotNull(type);
            DebugCheck.NotNull(structuralTypeConfiguration);

            foreach (var convention in _configurationConventions)
            {
                var propertyTypeConfigurationConvention
                    = convention as IConfigurationConvention <Type, TStructuralTypeConfiguration>;

                if (propertyTypeConfigurationConvention != null)
                {
                    propertyTypeConfigurationConvention.Apply(type, structuralTypeConfiguration, modelConfiguration);
                }

                var structuralTypeConfigurationConvention
                    = convention as IConfigurationConvention <Type, StructuralTypeConfiguration>;

                if (structuralTypeConfigurationConvention != null)
                {
                    structuralTypeConfigurationConvention.Apply(type, structuralTypeConfiguration, modelConfiguration);
                }

                var lightweightConfigurationConvention
                    = convention as Convention;

                if (lightweightConfigurationConvention != null)
                {
                    lightweightConfigurationConvention.ApplyTypeConfiguration(type, structuralTypeConfiguration, modelConfiguration);
                }
            }
        }
        internal virtual void ApplyModelConfiguration(Type type, ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(type);
            DebugCheck.NotNull(modelConfiguration);

            foreach (var convention in _configurationConventions)
            {
                var modelConfigurationConvention
                    = convention as IConfigurationConvention <Type>;

                if (modelConfigurationConvention != null)
                {
                    modelConfigurationConvention.Apply(type, modelConfiguration);
                }

                var lightweightConfigurationConvention
                    = convention as Convention;

                if (lightweightConfigurationConvention != null)
                {
                    lightweightConfigurationConvention.ApplyModelConfiguration(type, modelConfiguration);
                }
            }
        }
Пример #51
0
        internal virtual void ApplyPropertyConfiguration(PropertyInfo propertyInfo, ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(propertyInfo);
            DebugCheck.NotNull(modelConfiguration);

            foreach (var convention in ((IList <IConvention>)_configurationConventions).Reverse())
            {
                var propertyConfigurationConvention
                    = convention as IConfigurationConvention <PropertyInfo>;

                if (propertyConfigurationConvention != null)
                {
                    propertyConfigurationConvention.Apply(propertyInfo, modelConfiguration);
                }

                var lightweightConfigurationConvention
                    = convention as Convention;

                if (lightweightConfigurationConvention != null)
                {
                    lightweightConfigurationConvention.ApplyPropertyConfiguration(propertyInfo, modelConfiguration);
                }
            }
        }
        internal ConfigurationRegistrar(ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(modelConfiguration);

            _modelConfiguration = modelConfiguration;
        }
Пример #53
0
 internal virtual void ApplyModelConfiguration(Type type, System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration)
 {
     this._conventionsConfiguration.ApplyModelConfiguration(type, modelConfiguration);
 }
Пример #54
0
        internal virtual void ApplyPropertyConfiguration(
            PropertyInfo propertyInfo, Func <PropertyConfiguration> propertyConfiguration, ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(propertyInfo);
            DebugCheck.NotNull(propertyConfiguration);

            var propertyConfigurationType
                = StructuralTypeConfiguration.GetPropertyConfigurationType(propertyInfo.PropertyType);

            foreach (var convention in ((IList <IConvention>)_configurationConventions).Reverse())
            {
                new PropertyConfigurationConventionDispatcher(
                    convention, propertyConfigurationType, propertyInfo, propertyConfiguration, modelConfiguration)
                .Dispatch();

                var lightweightConfigurationConvention
                    = convention as Convention;

                if (lightweightConfigurationConvention != null)
                {
                    lightweightConfigurationConvention.ApplyPropertyConfiguration(propertyInfo, propertyConfiguration, modelConfiguration);
                }
            }
        }
Пример #55
0
 private DbModelBuilder(DbModelBuilder source)
 {
     this._modelConfiguration       = source._modelConfiguration.Clone();
     this._conventionsConfiguration = source._conventionsConfiguration.Clone();
     this._modelBuilderVersion      = source._modelBuilderVersion;
 }
Пример #56
0
 internal DbModelBuilder(
     System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration,
     DbModelBuilderVersion modelBuilderVersion = DbModelBuilderVersion.Latest)
     : this(modelConfiguration, new ConventionsConfiguration(DbModelBuilder.SelectConventionSet(modelBuilderVersion)), modelBuilderVersion)
 {
 }
Пример #57
0
 protected override void ApplyCore(Type memberInfo, System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration modelConfiguration)
 {
     this._entityConfigurationAction(new ConventionTypeConfiguration(memberInfo, modelConfiguration));
 }
 internal ConventionTypeConfiguration(
     Type type,
     ModelConfiguration modelConfiguration)
     : this(type, null, null, modelConfiguration)
 {
 }
        internal virtual void ApplyPropertyConfiguration(
            PropertyInfo propertyInfo, Func <PropertyConfiguration> propertyConfiguration, ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(propertyInfo);
            DebugCheck.NotNull(propertyConfiguration);

            var propertyConfigurationType
                = StructuralTypeConfiguration.GetPropertyConfigurationType(propertyInfo.PropertyType);

            // PERF: this code is part of a critical path, consider its performance when refactoring
            for (var i = _configurationConventions.Count - 1; i >= 0; --i)
            {
                var convention = _configurationConventions[i];
                new PropertyConfigurationConventionDispatcher(
                    convention, propertyConfigurationType, propertyInfo, propertyConfiguration, modelConfiguration)
                .Dispatch();

                var lightweightConfigurationConvention
                    = convention as Convention;

                if (lightweightConfigurationConvention != null)
                {
                    lightweightConfigurationConvention.ApplyPropertyConfiguration(propertyInfo, propertyConfiguration, modelConfiguration);
                }
            }
        }