当前位置: 首页>>代码示例>>C#>>正文


C# Configuration.ModelConfiguration类代码示例

本文整理汇总了C#中System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration的典型用法代码示例。如果您正苦于以下问题:C# ModelConfiguration类的具体用法?C# ModelConfiguration怎么用?C# ModelConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ModelConfiguration类属于System.Data.Entity.ModelConfiguration.Configuration命名空间,在下文中一共展示了ModelConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure_should_uniquify_unconfigured_assocation_function_names

        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"));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:60,代码来源:ModelConfigurationTests.cs

示例2: ApplyCore

        protected override void ApplyCore(Type memberInfo, ModelConfiguration modelConfiguration)
        {
            DebugCheck.NotNull(memberInfo);
            DebugCheck.NotNull(modelConfiguration);

            _entityConfigurationAction(new ConventionTypeConfiguration(memberInfo, modelConfiguration));
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:7,代码来源:TypeConvention.cs

示例3: Map_should_create_association_sets_for_associations

        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);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:25,代码来源:NavigationPropertyMapperTests.cs

示例4: Apply_ignores_constraint_when_inverse_constraint_already_specified

        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);
        }
开发者ID:junxy,项目名称:entityframework,代码行数:26,代码来源:ForeignKeyAttributeConventionTests.cs

示例5: Apply_ignores_constraint_when_inverse_constraint_already_specified

        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);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:25,代码来源:ForeignKeyAttributeConventionTests.cs

示例6: ConventionTypeConfiguration

 internal ConventionTypeConfiguration(
     Type type,
     Func<ComplexTypeConfiguration> complexTypeConfiguration,
     ModelConfiguration modelConfiguration)
     : this(type, null, complexTypeConfiguration, modelConfiguration)
 {
     DebugCheck.NotNull(complexTypeConfiguration);
 }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:8,代码来源:ConventionTypeConfiguration.cs

示例7: ConfigureEdmMetadata

        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
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:8,代码来源:EdmMetadataContext.cs

示例8: ConfigureEdmMetadata

        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
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:8,代码来源:EdmMetadataContext.cs

示例9: ModelConfiguration

        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;
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:9,代码来源:ModelConfiguration.cs

示例10: Apply_should_set_model_namespace

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

            convention.Apply(modelConfiguration);

            Assert.Equal("Foo", modelConfiguration.ModelNamespace);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:9,代码来源:ModelNamespaceConventionTests.cs

示例11: Add_entity_configuration_should_add_to_model_configuration

        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)));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:9,代码来源:ConfigurationRegistrarTests.cs

示例12: Add_complex_type_configuration_should_add_to_model_configuration

        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)));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:9,代码来源:ConfigurationRegistrarTests.cs

示例13: ApplyCore

        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));
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:9,代码来源:PropertyConvention.cs

示例14: Configure_should_uniquify_unconfigured_association_function_names

        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"));
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:57,代码来源:ModelConfigurationTests.cs

示例15: IsComplexType_configures

        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)));
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:10,代码来源:ConventionTypeConfigurationOfTypeTests.cs


注:本文中的System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。