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


C# EdmModel.AddAssociationSet方法代码示例

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


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

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

示例2: GetAssociationSet_should_return_association_set

        public void GetAssociationSet_should_return_association_set()
        {
            var model = new EdmModel().Initialize();
            var entityType = model.AddEntityType("Foo");
            model.AddEntitySet("FooSet", entityType);
            var associationType = new EdmAssociationType().Initialize();
            associationType.SourceEnd.EntityType = entityType;
            associationType.TargetEnd.EntityType = entityType;
            model.AddAssociationSet("FooSet", associationType);

            var associationSet = model.GetAssociationSet(associationType);

            Assert.NotNull(associationSet);
            Assert.Same(associationType, associationSet.ElementType);
        }
开发者ID:junxy,项目名称:entityframework,代码行数:15,代码来源:EdmModelExtensionsTests.cs

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

示例4: Generate_can_map_independent_association_type

        public void Generate_can_map_independent_association_type()
        {
            var model = new EdmModel().Initialize();
            var principalEntityType = model.AddEntityType("P");
            principalEntityType.SetClrType(typeof(object));
            var idProperty1 = principalEntityType.AddPrimitiveProperty("Id1");
            idProperty1.PropertyType.EdmType = EdmPrimitiveType.Int32;
            principalEntityType.DeclaredKeyProperties.Add(idProperty1);
            var idProperty2 = principalEntityType.AddPrimitiveProperty("Id2");
            idProperty2.PropertyType.EdmType = EdmPrimitiveType.String;
            principalEntityType.DeclaredKeyProperties.Add(idProperty2);
            var dependentEntityType = model.AddEntityType("D");
            dependentEntityType.SetClrType(typeof(string));
            model.AddEntitySet("PSet", principalEntityType);
            model.AddEntitySet("DSet", dependentEntityType);
            var associationType
                = model.AddAssociationType("P_D",
                    principalEntityType, EdmAssociationEndKind.Required,
                    dependentEntityType, EdmAssociationEndKind.Many);
            model.AddAssociationSet("P_DSet", associationType);
            associationType.SourceEnd.DeleteAction = EdmOperationAction.Cascade;

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

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

            Assert.Equal(2, foreignKeyConstraint.DependentColumns.Count);
            Assert.Equal(associationType.Name, foreignKeyConstraint.Name);
            Assert.Equal(1, databaseMapping.EntityContainerMappings.Single().AssociationSetMappings.Count());
            Assert.Equal(DbOperationAction.Cascade, foreignKeyConstraint.DeleteAction);

            var foreignKeyColumn = foreignKeyConstraint.DependentColumns.First();

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


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