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


C# AssociationType.MarkPrincipalConfigured方法代码示例

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


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

示例1: Apply_should_introduce_constraint_when_one_to_one

        public void Apply_should_introduce_constraint_when_one_to_one()
        {
            var entityType1 = new EntityType("E", "N", DataSpace.CSpace);
            entityType1.AddKeyMember(EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)));

            var entityType2 = new EntityType("E", "N", DataSpace.CSpace);
            entityType2.AddKeyMember(EdmProperty.Primitive("P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)));

            var associationType = new AssociationType("A", XmlConstants.ModelNamespace_3, false, DataSpace.CSpace);
            associationType.SourceEnd = new AssociationEndMember("S", entityType2);
            associationType.TargetEnd = new AssociationEndMember("T", entityType1);

            associationType.MarkPrincipalConfigured();

            ((IEdmConvention<AssociationType>)new OneToOneConstraintIntroductionConvention())
                .Apply(associationType, new EdmModel(DataSpace.CSpace));

            Assert.NotNull(associationType.Constraint);
            Assert.Equal(1, associationType.Constraint.ToProperties.Count);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:20,代码来源:OneToOneConstraintIntroductionConventionTests.cs

示例2: ConfigureDependentBehavior

        private void ConfigureDependentBehavior(
            AssociationType associationType, EdmModel model, EntityTypeConfiguration entityTypeConfiguration)
        {
            DebugCheck.NotNull(associationType);
            DebugCheck.NotNull(model);
            DebugCheck.NotNull(entityTypeConfiguration);

            AssociationEndMember principalEnd;
            AssociationEndMember dependentEnd;

            if (!associationType.TryGuessPrincipalAndDependentEnds(out principalEnd, out dependentEnd))
            {
                if (IsNavigationPropertyDeclaringTypePrincipal.HasValue)
                {
                    associationType.MarkPrincipalConfigured();

                    var navProp = model.Namespaces
                                       .SelectMany(ns => ns.EntityTypes)
                                       .SelectMany(et => et.DeclaredNavigationProperties)
                                       .Single(np => np.GetClrPropertyInfo().IsSameAs(NavigationProperty));

                    principalEnd = IsNavigationPropertyDeclaringTypePrincipal.Value
                                       ? associationType.GetOtherEnd(navProp.ResultEnd)
                                       : navProp.ResultEnd;

                    dependentEnd = associationType.GetOtherEnd(principalEnd);

                    if (associationType.SourceEnd != principalEnd)
                    {
                        // need to move around source to be principal, target to be dependent so Edm services will use the correct
                        // principal and dependent ends. The Edm default Db + mapping service tries to guess principal/dependent
                        // based on multiplicities, but if it can't figure it out, it will use source as principal and target as dependent
                        associationType.SourceEnd = principalEnd;
                        associationType.TargetEnd = dependentEnd;

                        var associationSet
                            = model.Containers
                                   .SelectMany(ct => ct.AssociationSets)
                                   .Single(aset => aset.ElementType == associationType);

                        var sourceSet = associationSet.SourceSet;

                        associationSet.SourceSet = associationSet.TargetSet;
                        associationSet.TargetSet = sourceSet;
                    }
                }

                if (principalEnd == null)
                {
                    dependentEnd = associationType.TargetEnd;
                }
            }

            ConfigureConstraint(associationType, dependentEnd, entityTypeConfiguration);
            ConfigureDeleteAction(associationType.GetOtherEnd(dependentEnd));
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:56,代码来源:NavigationPropertyConfiguration.cs


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