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


C# EdmModel.AddEntityType方法代码示例

本文整理汇总了C#中System.Data.Entity.Core.Metadata.Edm.EdmModel.AddEntityType方法的典型用法代码示例。如果您正苦于以下问题:C# EdmModel.AddEntityType方法的具体用法?C# EdmModel.AddEntityType怎么用?C# EdmModel.AddEntityType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.Entity.Core.Metadata.Edm.EdmModel的用法示例。


在下文中一共展示了EdmModel.AddEntityType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HasCascadeDeletePath_should_return_true_for_transitive_cascade

        public void HasCascadeDeletePath_should_return_true_for_transitive_cascade()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityTypeA = model.AddEntityType("A");
            var entityTypeB = model.AddEntityType("B");
            var entityTypeC = model.AddEntityType("B");
            var associationTypeA
                = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
                      {
                          SourceEnd = new AssociationEndMember("S", entityTypeA),
                          TargetEnd = new AssociationEndMember("T", entityTypeB)
                      };

            associationTypeA.SourceEnd.DeleteBehavior = OperationAction.Cascade;
            model.AddAssociationType(associationTypeA);
            var associationTypeB
                = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
                      {
                          SourceEnd = new AssociationEndMember("S", entityTypeB),
                          TargetEnd = new AssociationEndMember("T", entityTypeC)
                      };

            associationTypeB.SourceEnd.DeleteBehavior = OperationAction.Cascade;
            model.AddAssociationType(associationTypeB);

            Assert.True(model.HasCascadeDeletePath(entityTypeA, entityTypeB));
            Assert.True(model.HasCascadeDeletePath(entityTypeB, entityTypeC));
            Assert.True(model.HasCascadeDeletePath(entityTypeA, entityTypeC));
            Assert.False(model.HasCascadeDeletePath(entityTypeB, entityTypeA));
            Assert.False(model.HasCascadeDeletePath(entityTypeC, entityTypeB));
            Assert.False(model.HasCascadeDeletePath(entityTypeC, entityTypeA));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:32,代码来源:EdmModelExtensionsTests.cs

示例2: Generate_can_map_a_simple_entity_type_and_set

        public void Generate_can_map_a_simple_entity_type_and_set()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = model.AddEntityType("E");
            var type = typeof(object);

            entityType.GetMetadataProperties().SetClrType(type);
            var property = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);
            var property1 = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);
            var entitySet = model.AddEntitySet("ESet", entityType);

            var databaseMapping = CreateDatabaseMappingGenerator().Generate(model);

            var entitySetMapping = databaseMapping.GetEntitySetMapping(entitySet);

            Assert.NotNull(entitySetMapping);
            Assert.Same(entitySet, entitySetMapping.EntitySet);

            var entityTypeMapping = entitySetMapping.EntityTypeMappings.Single();

            Assert.Same(entityType, entityTypeMapping.EntityType);
            Assert.NotNull(entityTypeMapping.MappingFragments.Single().Table);
            Assert.Equal("E", entityTypeMapping.MappingFragments.Single().Table.Name);
            Assert.Equal(2, entityTypeMapping.MappingFragments.Single().Table.Properties.Count);
            Assert.Equal(typeof(object), entityTypeMapping.GetClrType());
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:30,代码来源:DatabaseMappingGeneratorTests.cs

示例3: Configure_should_configure_modification_functions

        public void Configure_should_configure_modification_functions()
        {
            var model = new EdmModel(DataSpace.CSpace);

            var entityType = model.AddEntityType("E");
            entityType.GetMetadataProperties().SetClrType(typeof(object));

            model.AddEntitySet("ESet", entityType);

            var modificationFunctionsConfigurationMock = new Mock<ModificationStoredProceduresConfiguration>();

            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            entityTypeConfiguration.MapToStoredProcedures(modificationFunctionsConfigurationMock.Object, true);

            entityType.SetConfiguration(entityTypeConfiguration);

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

            entityTypeConfiguration.Configure(entityType, databaseMapping, ProviderRegistry.Sql2008_ProviderManifest);

            modificationFunctionsConfigurationMock
                .Verify(
                    m => m.Configure(
                        It.IsAny<EntityTypeModificationFunctionMapping>(), It.IsAny<DbProviderManifest>()),
                    Times.Once());
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:27,代码来源:EntityTypeConfigurationTests.cs

示例4: Configure_should_configure_inverse

        public void Configure_should_configure_inverse()
        {
            var inverseMockPropertyInfo = new MockPropertyInfo();
            var navigationPropertyConfiguration = new NavigationPropertyConfiguration(new MockPropertyInfo())
                                                      {
                                                          InverseNavigationProperty = inverseMockPropertyInfo
                                                      };
            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            associationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var inverseAssociationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            inverseAssociationType.SourceEnd = new AssociationEndMember("S", new EntityType("E", "N", DataSpace.CSpace));
            inverseAssociationType.TargetEnd = new AssociationEndMember("T", new EntityType("E", "N", DataSpace.CSpace));
            var model = new EdmModel(DataSpace.CSpace);
            model.AddAssociationType(inverseAssociationType);
            var inverseNavigationProperty
                = model.AddEntityType("T")
                       .AddNavigationProperty("N", inverseAssociationType);
            inverseNavigationProperty.SetClrPropertyInfo(inverseMockPropertyInfo);

            navigationPropertyConfiguration.Configure(
                new NavigationProperty("N", TypeUsage.Create(associationType.TargetEnd.GetEntityType()))
                    {
                        RelationshipType = associationType
                    }, model, new EntityTypeConfiguration(typeof(object)));

            Assert.Same(associationType, inverseNavigationProperty.Association);
            Assert.Same(associationType.SourceEnd, inverseNavigationProperty.ResultEnd);
            Assert.Same(associationType.TargetEnd, inverseNavigationProperty.FromEndMember);
            Assert.Equal(0, model.AssociationTypes.Count());
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:31,代码来源:NavigationPropertyConfigurationTests.cs

示例5: Generate_can_map_a_simple_entity_type_and_set

        public void Generate_can_map_a_simple_entity_type_and_set()
        {
            var model = new EdmModel().Initialize();
            var entityType = model.AddEntityType("E");
            var type = typeof(object);

            entityType.Annotations.SetClrType(type);
            var property = EdmProperty.Primitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);
            var property1 = EdmProperty.Primitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);
            var entitySet = model.AddEntitySet("ESet", entityType);

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

            var entitySetMapping = databaseMapping.GetEntitySetMapping(entitySet);

            Assert.NotNull(entitySetMapping);
            Assert.Same(entitySet, entitySetMapping.EntitySet);

            var entityTypeMapping = entitySetMapping.EntityTypeMappings.Single();

            Assert.Same(entityType, entityTypeMapping.EntityType);
            Assert.NotNull(entityTypeMapping.MappingFragments.Single().Table);
            Assert.Equal("E", entityTypeMapping.MappingFragments.Single().Table.Name);
            Assert.Equal(2, entityTypeMapping.MappingFragments.Single().Table.Properties.Count);
            Assert.Equal(typeof(object), entityTypeMapping.GetClrType());
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:30,代码来源:DatabaseMappingGeneratorTests.cs

示例6: 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

示例7: Configure_should_uniquify_unconfigured_function_names

        public void Configure_should_uniquify_unconfigured_function_names()
        {
            var modelConfiguration = new ModelConfiguration();

            var typeA = new MockType("A");
            var typeB = new MockType("B");

            modelConfiguration.Entity(typeA).MapToStoredProcedures();

            var modificationFunctionsConfiguration
                = new ModificationStoredProceduresConfiguration();

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

            modificationFunctionsConfiguration.Insert(modificationFunctionConfiguration);

            modelConfiguration.Entity(typeB).MapToStoredProcedures(modificationFunctionsConfiguration, true);

            var model = new EdmModel(DataSpace.CSpace);

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

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

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

            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 == "A_Insert"));
            Assert.True(databaseMapping.Database.Functions.Any(f => f.StoreFunctionNameAttribute == "A_Insert1"));
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:41,代码来源:ModelConfigurationTests.cs

示例8: HasCascadeDeletePath_should_return_true_for_self_ref_cascade

        public void HasCascadeDeletePath_should_return_true_for_self_ref_cascade()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = model.AddEntityType("A");
            var associationType
                = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace)
                      {
                          SourceEnd = new AssociationEndMember("S", entityType)
                      };
            associationType.TargetEnd = new AssociationEndMember("T", associationType.SourceEnd.GetEntityType());

            associationType.SourceEnd.DeleteBehavior = OperationAction.Cascade;
            model.AddAssociationType(associationType);

            Assert.True(model.HasCascadeDeletePath(entityType, entityType));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:16,代码来源:EdmModelExtensionsTests.cs

示例9: CreateSimpleModel

        private static DbDatabaseMapping CreateSimpleModel(double version)
        {
            var model = new EdmModel(DataSpace.CSpace, version);

            var entityType = model.AddEntityType("E");
            var type = typeof(object);

            entityType.GetMetadataProperties().SetClrType(type);
            model.AddEntitySet("ESet", entityType);

            var property1 = EdmProperty.CreatePrimitive("Id", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property1);
            var property = property1;
            property.Nullable = false;
            entityType.AddKeyMember(property);

            return new DatabaseMappingGenerator(ProviderRegistry.Sql2008_ProviderInfo, ProviderRegistry.Sql2008_ProviderManifest).Generate(model);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:19,代码来源:EdmxSerializerTests.cs

示例10: Apply_generates_constraint_when_simple_fk

        public void Apply_generates_constraint_when_simple_fk()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = model.AddEntityType("E");
            var associationType = model.AddAssociationType(
                "A",
                entityType, RelationshipMultiplicity.ZeroOrOne,
                entityType, RelationshipMultiplicity.Many);
            var navigationProperty = entityType.AddNavigationProperty("N", associationType);
            var property = EdmProperty.Primitive("Fk", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);
            var fkProperty = property;
            var foreignKeyAnnotation = new ForeignKeyAttribute("Fk");
            navigationProperty.Annotations.SetClrAttributes(new[] { foreignKeyAnnotation });

            ((IEdmConvention<NavigationProperty>)new ForeignKeyNavigationPropertyAttributeConvention())
                .Apply(navigationProperty, model);

            Assert.NotNull(associationType.Constraint);
            Assert.True(associationType.Constraint.ToProperties.Contains(fkProperty));
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:22,代码来源:ForeignKeyAnnotationConventionTests.cs

示例11: Generate_should_correctly_map_string_primitive_property_facets

        public void Generate_should_correctly_map_string_primitive_property_facets()
        {
            var model = new EdmModel().Initialize();
            var entityType = model.AddEntityType("E");
            var type = typeof(object);

            entityType.Annotations.SetClrType(type);
            model.AddEntitySet("ESet", entityType);

            var property
                = EdmProperty
                    .Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);

            property.Nullable = false;
            property.IsFixedLength = true;
            property.IsMaxLength = true;
            property.IsUnicode = true;
            property.MaxLength = 42;
            property.Precision = 23;
            property.Scale = 77;
            property.SetStoreGeneratedPattern(StoreGeneratedPattern.Identity);

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

            var column = databaseMapping.GetEntityTypeMapping(entityType).MappingFragments.Single().ColumnMappings.Single().ColumnProperty;

            Assert.False(column.Nullable);
            Assert.Null(column.IsFixedLength);
            Assert.Equal(false, column.IsMaxLength);
            Assert.Null(column.IsUnicode);
            Assert.Equal(42, column.MaxLength);
            Assert.Null(column.Precision);
            Assert.Null(column.Scale);
            Assert.Equal(StoreGeneratedPattern.Identity, column.StoreGeneratedPattern);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:37,代码来源:DatabaseMappingGeneratorTests.cs

示例12: Generate_should_correctly_map_string_primitive_property_facets

        public void Generate_should_correctly_map_string_primitive_property_facets()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = model.AddEntityType("E");
            var type = typeof(object);

            entityType.GetMetadataProperties().SetClrType(type);
            model.AddEntitySet("ESet", entityType);

            var property
                = EdmProperty
                    .CreatePrimitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType.AddMember(property);

            property.Nullable = false;
            property.IsFixedLength = true;
            property.IsMaxLength = true;
            property.IsUnicode = true;
            property.MaxLength = 42;
            property.Precision = 23;
            property.Scale = 77;
            property.SetStoreGeneratedPattern(StoreGeneratedPattern.Identity);

            var databaseMapping = CreateDatabaseMappingGenerator().Generate(model);

            var column = databaseMapping.GetEntityTypeMapping(entityType).MappingFragments.Single().ColumnMappings.Single().ColumnProperty;

            Assert.False(column.Nullable);
            Assert.True(column.IsFixedLengthConstant);
            Assert.False(column.IsMaxLength);
            Assert.True(column.IsUnicodeConstant);
            Assert.Equal(42, column.MaxLength);
            Assert.Null(column.Precision);
            Assert.Null(column.Scale);
            Assert.Equal(StoreGeneratedPattern.Identity, column.StoreGeneratedPattern);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:37,代码来源:DatabaseMappingGeneratorTests.cs

示例13: Generate_should_not_generate_modification_function_mappings_when_entity_abstract

        public void Generate_should_not_generate_modification_function_mappings_when_entity_abstract()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var entityType = model.AddEntityType("E");
            entityType.Abstract = true;
            entityType.GetMetadataProperties().SetClrType(typeof(string));
            
            var derivedType = model.AddEntityType("D");
            derivedType.BaseType = entityType;
            derivedType.GetMetadataProperties().SetClrType(typeof(object));

            model.AddEntitySet("ESet", entityType);

            var entityTypeConfiguration = new EntityTypeConfiguration(typeof(object));
            entityTypeConfiguration.MapToStoredProcedures();
            entityType.SetConfiguration(entityTypeConfiguration);

            var databaseMapping = CreateDatabaseMappingGenerator().Generate(model);

            Assert.Equal(0, databaseMapping.Database.Functions.Count());
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:21,代码来源:DatabaseMappingGeneratorTests.cs

示例14: Generate_maps_abstract_type_hierarchies_correctly

        public void Generate_maps_abstract_type_hierarchies_correctly()
        {
            var model = new EdmModel(DataSpace.CSpace);

            var rootEntityType = model.AddEntityType("E");

            rootEntityType.GetMetadataProperties().SetClrType(typeof(object));

            var property0
                = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            rootEntityType.AddMember(property0);
            rootEntityType.AddKeyMember(rootEntityType.Properties.First());

            var property1
                = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            rootEntityType.AddMember(property1);

            model.AddEntitySet("ESet", rootEntityType);

            var entityType2 = model.AddEntityType("E2");

            var property2
                = EdmProperty.CreatePrimitive("P3", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType2.AddMember(property2);
            entityType2.GetMetadataProperties().SetClrType(typeof(string));
            entityType2.Abstract = true;
            entityType2.BaseType = rootEntityType;

            var entityType3 = model.AddEntityType("E3");

            entityType3.GetMetadataProperties().SetClrType(typeof(int));

            var property3
                = EdmProperty.CreatePrimitive("P4", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType3.AddMember(property3);
            entityType3.BaseType = entityType2;

            var databaseMapping = CreateDatabaseMappingGenerator().Generate(model);

            var entityType1Mapping = databaseMapping.GetEntityTypeMapping(rootEntityType);
            var entityType3Mapping = databaseMapping.GetEntityTypeMapping(entityType3);

            Assert.Equal(2, entityType1Mapping.MappingFragments.Single().ColumnMappings.Count());
            Assert.Equal("P1", entityType1Mapping.MappingFragments.Single().ColumnMappings.ElementAt(0).ColumnProperty.Name);
            Assert.Equal("P2", entityType1Mapping.MappingFragments.Single().ColumnMappings.ElementAt(1).ColumnProperty.Name);

            Assert.Equal(4, entityType3Mapping.MappingFragments.Single().ColumnMappings.Count());
            Assert.Equal("P1", entityType3Mapping.MappingFragments.Single().ColumnMappings.ElementAt(0).ColumnProperty.Name);
            Assert.Equal("P2", entityType3Mapping.MappingFragments.Single().ColumnMappings.ElementAt(1).ColumnProperty.Name);
            Assert.Equal("P3", entityType3Mapping.MappingFragments.Single().ColumnMappings.ElementAt(2).ColumnProperty.Name);
            Assert.Equal("P4", entityType3Mapping.MappingFragments.Single().ColumnMappings.ElementAt(3).ColumnProperty.Name);

            var table = entityType1Mapping.MappingFragments.Single().Table;

            Assert.Equal(5, table.Properties.Count);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:60,代码来源:DatabaseMappingGeneratorTests.cs

示例15: Generate_can_map_type_hierarchies_using_Tph

        public void Generate_can_map_type_hierarchies_using_Tph()
        {
            var model = new EdmModel(DataSpace.CSpace);
            var rootEntityType = model.AddEntityType("E");
            var type = typeof(object);

            rootEntityType.GetMetadataProperties().SetClrType(type);
            var property = EdmProperty.CreatePrimitive("P1", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            rootEntityType.AddMember(property);
            var property1 = EdmProperty.CreatePrimitive("P2", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            rootEntityType.AddMember(property1);
            var entitySet = model.AddEntitySet("ESet", rootEntityType);
            var entityType2 = model.AddEntityType("E2");
            var property2 = EdmProperty.CreatePrimitive("P3", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType2.AddMember(property2);
            var type1 = typeof(string);

            entityType2.GetMetadataProperties().SetClrType(type1);
            entityType2.BaseType = rootEntityType;
            var entityType3 = model.AddEntityType("E3");
            var type2 = typeof(int);

            entityType3.GetMetadataProperties().SetClrType(type2);
            var property3 = EdmProperty.CreatePrimitive("P4", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            entityType3.AddMember(property3);
            entityType3.BaseType = entityType2;

            var databaseMapping = CreateDatabaseMappingGenerator().Generate(model);

            var entitySetMapping = databaseMapping.GetEntitySetMapping(entitySet);

            Assert.NotNull(entitySetMapping);
            var entityTypeMappings = entitySetMapping.EntityTypeMappings;

            Assert.Equal(3, entityTypeMappings.Count());

            var entityType1Mapping = databaseMapping.GetEntityTypeMapping(rootEntityType);
            var entityType2Mapping = databaseMapping.GetEntityTypeMapping(entityType2);
            var entityType3Mapping = databaseMapping.GetEntityTypeMapping(entityType3);

            Assert.Equal(2, entityType1Mapping.MappingFragments.Single().ColumnMappings.Count());
            Assert.Equal(3, entityType2Mapping.MappingFragments.Single().ColumnMappings.Count());
            Assert.Equal(4, entityType3Mapping.MappingFragments.Single().ColumnMappings.Count());

            var table = entityType1Mapping.MappingFragments.Single().Table;
            Assert.Same(table, entityType2Mapping.MappingFragments.Single().Table);
            Assert.Same(table, entityType3Mapping.MappingFragments.Single().Table);
            Assert.Equal(5, table.Properties.Count);
            Assert.Equal("P1", table.Properties[0].Name);
            Assert.Equal("P2", table.Properties[1].Name);
            Assert.Equal("P3", table.Properties[2].Name);
            Assert.Equal("P4", table.Properties[3].Name);
            Assert.Equal("Discriminator", table.Properties[4].Name);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:58,代码来源:DatabaseMappingGeneratorTests.cs


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