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


C# AssociationType.AddMember方法代码示例

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


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

示例1: Create_should_return_only_fk_associations

            public void Create_should_return_only_fk_associations()
            {
                var filter = new ViewgenContext.OneToOneFkAssociationsForEntitiesFilter();

                var associationType1
                    = new AssociationType("A1", EdmConstants.TransientNamespace, true, DataSpace.CSpace);

                var entityType = new EntityType("E", "N", DataSpace.CSpace);

                associationType1.AddMember(
                    new AssociationEndMember("S", entityType)
                        {
                            RelationshipMultiplicity = RelationshipMultiplicity.One
                        });
                associationType1.AddMember(
                    new AssociationEndMember("T", entityType)
                        {
                            RelationshipMultiplicity = RelationshipMultiplicity.One
                        });

                associationType1.SetReadOnly();

                var associationSet1 = new AssociationSet("AS1", associationType1);

                var associationType2
                    = new AssociationType("A2", EdmConstants.TransientNamespace, false, DataSpace.CSpace);

                associationType2.AddMember(
                    new AssociationEndMember("S", entityType)
                        {
                            RelationshipMultiplicity = RelationshipMultiplicity.One
                        });
                associationType2.AddMember(
                    new AssociationEndMember("T", entityType)
                        {
                            RelationshipMultiplicity = RelationshipMultiplicity.One
                        });

                associationType2.SetReadOnly();

                var associationSet2 = new AssociationSet("AS2", associationType2);

                var query
                    = filter.Filter(
                        new[] { entityType },
                        new[] { associationSet1, associationSet2 });

                Assert.Same(associationSet1, query.Single());
            }
开发者ID:christiandpena,项目名称:entityframework,代码行数:49,代码来源:ViewgenContextTests.cs

示例2: TranslateColumnMap_returns_correct_columntypes_and_nullablecolumns_for_associations

        public void TranslateColumnMap_returns_correct_columntypes_and_nullablecolumns_for_associations()
        {
            var metadataWorkspaceMock = new Mock<MetadataWorkspace>();
            metadataWorkspaceMock.Setup(m => m.GetQueryCacheManager()).Returns(QueryCacheManager.Create());

            var codeFirstOSpaceTypeFactory = new CodeFirstOSpaceTypeFactory();
            var refEntityColumnMap = (EntityColumnMap)BuildSimpleEntitySetColumnMap(metadataWorkspaceMock, codeFirstOSpaceTypeFactory).Element;
            
            var cSpaceEntityType = new EntityType(typeof(RefEntity).Name, "N", DataSpace.CSpace);
            cSpaceEntityType.AddMember(new EdmProperty("Id", TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32))));

            var navigationProperty = new NavigationProperty("SimpleEntity", TypeUsage.Create(refEntityColumnMap.Type.EdmType));
            var associationType = new AssociationType("A", "N", false, DataSpace.CSpace);
            associationType.AddMember(
                new AssociationEndMember("From", new RefType(cSpaceEntityType), RelationshipMultiplicity.One));
            associationType.AddMember(
                new AssociationEndMember("To", new RefType((EntityType)navigationProperty.TypeUsage.EdmType), RelationshipMultiplicity.One));
            associationType.SetReadOnly();

            navigationProperty.RelationshipType = associationType;
            navigationProperty.FromEndMember = associationType.RelationshipEndMembers[0];
            navigationProperty.ToEndMember = associationType.RelationshipEndMembers[1];
            cSpaceEntityType.AddMember(navigationProperty);
            var entityTypeUsage = TypeUsage.Create(cSpaceEntityType);

            var oSpaceEntityType = codeFirstOSpaceTypeFactory.TryCreateType(typeof(RefEntity), cSpaceEntityType);
            codeFirstOSpaceTypeFactory.CspaceToOspace.Add(cSpaceEntityType, oSpaceEntityType);

            var associations = new EdmItemCollection();
            associations.AddInternal(associationType);

            codeFirstOSpaceTypeFactory.CreateRelationships(associations);
            foreach (var resolve in codeFirstOSpaceTypeFactory.ReferenceResolutions)
            {
                resolve();
            }

            var idScalarMap = new ScalarColumnMap(TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32)), "Id", 0, 1);
            var refColumnMap = new RefColumnMap(
                associationType.RelationshipEndMembers[1].TypeUsage, "E",
                new SimpleEntityIdentity(null, new SimpleColumnMap[] { idScalarMap }));
            var collectionMap = new SimpleCollectionColumnMap(
                entityTypeUsage, "MockCollectionType", refColumnMap, null, null);

            metadataWorkspaceMock.Setup(m => m.GetItem<EdmType>("N.RefEntity", DataSpace.OSpace))
                .Returns(oSpaceEntityType);

            var factory =
                new Translator().TranslateColumnMap<object>(
                    collectionMap, metadataWorkspaceMock.Object, new SpanIndex(), MergeOption.NoTracking, streaming: false, valueLayer: false);
            Assert.NotNull(factory);

            Assert.Equal(new[] { null, typeof(int) }, factory.ColumnTypes);
            Assert.Equal(new[] { false, true }, factory.NullableColumns);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:55,代码来源:TranslatorTests.cs


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