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


C# EdmModel.AddAssociationType方法代码示例

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


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

示例1: 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 EdmAssociationType().Initialize();
            var inverseAssociationType = new EdmAssociationType().Initialize();
            var model = new EdmModel().Initialize();
            model.AddAssociationType(inverseAssociationType);
            var inverseNavigationProperty
                = model.AddEntityType("T")
                    .AddNavigationProperty("N", inverseAssociationType);
            inverseNavigationProperty.SetClrPropertyInfo(inverseMockPropertyInfo);

            navigationPropertyConfiguration.Configure(
                new EdmNavigationProperty
                    {
                        Association = associationType
                    }, model, new EntityTypeConfiguration(typeof(object)));

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

示例2: HasCascadeDeletePath_should_return_true_for_self_ref_cascade

        public void HasCascadeDeletePath_should_return_true_for_self_ref_cascade()
        {
            var model = new EdmModel().Initialize();
            var entityType = model.AddEntityType("A");
            var associationType = new EdmAssociationType().Initialize();
            associationType.SourceEnd.EntityType
                = associationType.TargetEnd.EntityType
                  = entityType;
            associationType.SourceEnd.DeleteAction = EdmOperationAction.Cascade;
            model.AddAssociationType(associationType);

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

示例3: HasCascadeDeletePath_should_return_true_for_transitive_cascade

        public void HasCascadeDeletePath_should_return_true_for_transitive_cascade()
        {
            var model = new EdmModel().Initialize();
            var entityTypeA = model.AddEntityType("A");
            var entityTypeB = model.AddEntityType("B");
            var entityTypeC = model.AddEntityType("B");
            var associationTypeA = new EdmAssociationType().Initialize();
            associationTypeA.SourceEnd.EntityType = entityTypeA;
            associationTypeA.TargetEnd.EntityType = entityTypeB;
            associationTypeA.SourceEnd.DeleteAction = EdmOperationAction.Cascade;
            model.AddAssociationType(associationTypeA);
            var associationTypeB = new EdmAssociationType().Initialize();
            associationTypeB.SourceEnd.EntityType = entityTypeB;
            associationTypeB.TargetEnd.EntityType = entityTypeC;
            associationTypeB.SourceEnd.DeleteAction = EdmOperationAction.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:junxy,项目名称:entityframework,代码行数:24,代码来源:EdmModelExtensionsTests.cs

示例4: Apply_generates_constraint_when_simple_fk

        public void Apply_generates_constraint_when_simple_fk()
        {
            var model = new EdmModel().Initialize();
            var entityType = model.AddEntityType("E");
            var associationType = model.AddAssociationType("A",
                entityType, EdmAssociationEndKind.Optional,
                entityType, EdmAssociationEndKind.Many);
            var navigationProperty = entityType.AddNavigationProperty("N", associationType);
            var fkProperty = entityType.AddPrimitiveProperty("Fk");
            var foreignKeyAnnotation = new ForeignKeyAttribute("Fk");
            navigationProperty.Annotations.SetClrAttributes(new[] { foreignKeyAnnotation });

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

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

示例5: Apply_should_not_match_key_that_is_also_an_fk

        public void Apply_should_not_match_key_that_is_also_an_fk()
        {
            var model = new EdmModel().Initialize();
            var entityType = new EdmEntityType();
            var property = new EdmProperty().AsPrimitive();

            property.PropertyType.EdmType = EdmPrimitiveType.Int64;
            entityType.DeclaredKeyProperties.Add(property);

            var associationType
                = model.AddAssociationType(
                    "A", new EdmEntityType(), EdmAssociationEndKind.Optional,
                    entityType, EdmAssociationEndKind.Many);
            associationType.Constraint = new EdmAssociationConstraint();
            associationType.Constraint.DependentProperties.Add(property);

            ((IEdmConvention<EdmEntityType>)new StoreGeneratedIdentityKeyConvention())
                .Apply(entityType, model);

            Assert.Null(entityType.DeclaredKeyProperties.Single().GetStoreGeneratedPattern());
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:21,代码来源:StoreGeneratedIdentityKeyConventionTests.cs

示例6: Apply_throws_with_empty_foreign_key_properties

        public void Apply_throws_with_empty_foreign_key_properties()
        {
            var model = new EdmModel().Initialize();
            var entityType = model.AddEntityType("E");
            var mockType = new MockType();
            entityType.SetClrType(mockType);
            var associationType = model.AddAssociationType("A",
                entityType, EdmAssociationEndKind.Optional,
                entityType, EdmAssociationEndKind.Many);
            var navigationProperty = entityType.AddNavigationProperty("N", associationType);
            var foreignKeyAnnotation = new ForeignKeyAttribute(",");
            navigationProperty.Annotations.SetClrAttributes(new[] { foreignKeyAnnotation });

            Assert.Equal(Strings.ForeignKeyAttributeConvention_EmptyKey("N", mockType.Object), Assert.Throws<InvalidOperationException>(() => ((IEdmConvention<EdmNavigationProperty>)new ForeignKeyNavigationPropertyAttributeConvention())
                                                                                                                                                        .Apply(navigationProperty, model)).Message);
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:16,代码来源:ForeignKeyAnnotationConventionTests.cs

示例7: Apply_should_match_key_that_is_an_fk_used_in_table_splitting

        public void Apply_should_match_key_that_is_an_fk_used_in_table_splitting()
        {
            var model = new EdmModel().Initialize();
            var entityType = new EdmEntityType();
            var property = new EdmProperty().AsPrimitive();

            property.PropertyType.EdmType = EdmPrimitiveType.Int64;
            entityType.DeclaredKeyProperties.Add(property);

            var targetConfig = new EntityTypeConfiguration(typeof(object));
            targetConfig.ToTable("SharedTable");
            entityType.SetConfiguration(targetConfig);

            var sourceEntityType = new EdmEntityType();
            var sourceConfig = new EntityTypeConfiguration(typeof(object));
            sourceConfig.ToTable("SharedTable");
            sourceEntityType.SetConfiguration(sourceConfig);

            var associationType
                = model.AddAssociationType(
                    "A", sourceEntityType, EdmAssociationEndKind.Required,
                    entityType, EdmAssociationEndKind.Required);
            associationType.Constraint = new EdmAssociationConstraint();
            associationType.Constraint.DependentProperties.Add(property);

            ((IEdmConvention<EdmEntityType>)new StoreGeneratedIdentityKeyConvention())
                .Apply(entityType, model);

            Assert.Equal(
                DbStoreGeneratedPattern.Identity,
                entityType.DeclaredKeyProperties.Single().GetStoreGeneratedPattern());
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:32,代码来源:StoreGeneratedIdentityKeyConventionTests.cs

示例8: CreateModelFixture

        private static EdmModel CreateModelFixture(
            out EdmEntityType declaringEntityType, out EdmEntityType complexEntityType)
        {
            var model = new EdmModel().Initialize();

            declaringEntityType = model.AddEntityType("E");
            complexEntityType = model.AddEntityType("C");
            complexEntityType.AddPrimitiveProperty("P");

            var associationType
                = model.AddAssociationType(
                    "A",
                    declaringEntityType, EdmAssociationEndKind.Many,
                    complexEntityType, EdmAssociationEndKind.Optional);

            declaringEntityType.AddNavigationProperty("E.C", associationType);

            return model;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:19,代码来源:ComplexTypeDiscoveryConventionTests.cs

示例9: AddAssociationSet_should_create_and_add_to_default_container

        public void AddAssociationSet_should_create_and_add_to_default_container()
        {
            var model = new EdmModel().Initialize();
            var sourceEntityType = model.AddEntityType("Source");
            var targetEntityType = model.AddEntityType("Target");
            var associationType = model.AddAssociationType(
                "Foo",
                sourceEntityType, EdmAssociationEndKind.Required,
                targetEntityType, EdmAssociationEndKind.Many);

            var associationSet = model.AddAssociationSet("FooSet", associationType);

            Assert.NotNull(associationSet);
            Assert.Equal("FooSet", associationSet.Name);
            Assert.Same(associationType, associationSet.ElementType);

            Assert.True(model.Containers.Single().AssociationSets.Contains(associationSet));
        }
开发者ID:junxy,项目名称:entityframework,代码行数:18,代码来源:EdmModelExtensionsTests.cs

示例10: AddAssociationType_should_create_and_add_to_default_namespace

        public void AddAssociationType_should_create_and_add_to_default_namespace()
        {
            var model = new EdmModel().Initialize();
            var sourceEntityType = model.AddEntityType("Source");
            var targetEntityType = model.AddEntityType("Target");

            var associationType = model.AddAssociationType(
                "Foo",
                sourceEntityType, EdmAssociationEndKind.Required,
                targetEntityType, EdmAssociationEndKind.Many);

            Assert.NotNull(associationType);
            Assert.Equal("Foo", associationType.Name);
            Assert.Same(sourceEntityType, associationType.SourceEnd.EntityType);
            Assert.Equal(EdmAssociationEndKind.Required, associationType.SourceEnd.EndKind);
            Assert.Same(targetEntityType, associationType.TargetEnd.EntityType);
            Assert.Equal(EdmAssociationEndKind.Many, associationType.TargetEnd.EndKind);
            Assert.True(model.Namespaces.Single().AssociationTypes.Contains(associationType));
        }
开发者ID:junxy,项目名称:entityframework,代码行数:19,代码来源:EdmModelExtensionsTests.cs

示例11: RemoveAssociationType_should_remove_type_and_set

        public void RemoveAssociationType_should_remove_type_and_set()
        {
            var model = new EdmModel().Initialize();
            var associationType = model.AddAssociationType(
                "A",
                new EdmEntityType(), EdmAssociationEndKind.Optional,
                new EdmEntityType(), EdmAssociationEndKind.Many);
            model.AddAssociationSet("FooSet", associationType);

            model.RemoveAssociationType(associationType);

            Assert.Equal(0, model.GetAssociationTypes().Count());
            Assert.Equal(0, model.Containers.First().AssociationSets.Count());
        }
开发者ID:junxy,项目名称:entityframework,代码行数:14,代码来源:EdmModelExtensionsTests.cs

示例12: GetAssociationsBetween_should_return_matching_associations

        public void GetAssociationsBetween_should_return_matching_associations()
        {
            var model = new EdmModel().Initialize();

            var entityTypeA = model.AddEntityType("Foo");
            var entityTypeB = model.AddEntityType("Bar");

            Assert.Equal(0, model.GetAssociationTypesBetween(entityTypeA, entityTypeB).Count());

            model.AddAssociationType(
                "Foo_Bar",
                entityTypeA, EdmAssociationEndKind.Optional,
                entityTypeB, EdmAssociationEndKind.Many);

            model.AddAssociationType(
                "Bar_Foo",
                entityTypeB, EdmAssociationEndKind.Optional,
                entityTypeA, EdmAssociationEndKind.Many);

            Assert.Equal(2, model.GetAssociationTypesBetween(entityTypeA, entityTypeB).Count());
            Assert.Equal(2, model.GetAssociationTypesBetween(entityTypeB, entityTypeA).Count());
            Assert.Equal(0, model.GetAssociationTypesBetween(entityTypeA, entityTypeA).Count());
        }
开发者ID:junxy,项目名称:entityframework,代码行数:23,代码来源:EdmModelExtensionsTests.cs

示例13: Generate_can_map_foreign_key_association_type

        public void Generate_can_map_foreign_key_association_type()
        {
            var model = new EdmModel().Initialize();
            var principalEntityType = model.AddEntityType("P");
            principalEntityType.SetClrType(typeof(object));
            var dependentEntityType = model.AddEntityType("D");
            dependentEntityType.SetClrType(typeof(string));
            var dependentProperty1 = dependentEntityType.AddPrimitiveProperty("FK1");
            dependentProperty1.PropertyType.EdmType = EdmPrimitiveType.Int32;
            var dependentProperty2 = dependentEntityType.AddPrimitiveProperty("FK2");
            dependentProperty2.PropertyType.EdmType = EdmPrimitiveType.String;
            model.AddEntitySet("PSet", principalEntityType);
            model.AddEntitySet("DSet", dependentEntityType);
            var associationType
                = model.AddAssociationType("P_D",
                    principalEntityType, EdmAssociationEndKind.Required,
                    dependentEntityType, EdmAssociationEndKind.Many);
            associationType.Constraint
                = new EdmAssociationConstraint
                    {
                        DependentEnd = associationType.TargetEnd,
                        DependentProperties = new[] { dependentProperty1, dependentProperty2 },
                    };
            associationType.SourceEnd.DeleteAction = EdmOperationAction.Cascade;

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

            var dependentTable = databaseMapping.GetEntityTypeMapping(dependentEntityType).TypeMappingFragments.Single().Table;
            var foreignKeyConstraint = dependentTable.ForeignKeyConstraints.Single();

            Assert.Equal(2, dependentTable.Columns.Count());
            Assert.Equal(2, foreignKeyConstraint.DependentColumns.Count);
            Assert.Equal(DbOperationAction.Cascade, foreignKeyConstraint.DeleteAction);
            Assert.Equal(associationType.Name, foreignKeyConstraint.Name);

            var foreignKeyColumn = foreignKeyConstraint.DependentColumns.First();

            Assert.False(foreignKeyColumn.IsNullable);
            Assert.Equal("FK1", foreignKeyColumn.Name);
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:40,代码来源:DatabaseMappingGeneratorTests.cs


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