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


C# EdmModel.GetAssociationTypes方法代码示例

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


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

示例1: Apply

        public void Apply(EdmModel model)
        {
            Check.NotNull(model, "model");

            var associationPairs
                = (from a1 in model.GetAssociationTypes()
                   from a2 in model.GetAssociationTypes()
                   where a1 != a2
                   where a1.SourceEnd.GetEntityType() == a2.TargetEnd.GetEntityType()
                         && a1.TargetEnd.GetEntityType() == a2.SourceEnd.GetEntityType()
                   let a1Configuration = a1.GetConfiguration() as NavigationPropertyConfiguration
                   let a2Configuration = a2.GetConfiguration() as NavigationPropertyConfiguration
                   where (((a1Configuration == null)
                           || ((a1Configuration.InverseEndKind == null)
                               && (a1Configuration.InverseNavigationProperty == null)))
                          && ((a2Configuration == null)
                              || ((a2Configuration.InverseEndKind == null)
                                  && (a2Configuration.InverseNavigationProperty == null))))
                   select new
                              {
                                  a1,
                                  a2
                              })
                    .Distinct((a, b) => a.a1 == b.a2 && a.a2 == b.a1)
                    .GroupBy(
                        (a, b) => a.a1.SourceEnd.GetEntityType() == b.a2.TargetEnd.GetEntityType()
                                  && a.a1.TargetEnd.GetEntityType() == b.a2.SourceEnd.GetEntityType())
                    .Where(g => g.Count() == 1)
                    .Select(g => g.Single());

            foreach (var pair in associationPairs)
            {
                var unifiedAssociation = pair.a2.GetConfiguration() != null ? pair.a2 : pair.a1;
                var redundantAssociation = unifiedAssociation == pair.a1 ? pair.a2 : pair.a1;

                unifiedAssociation.SourceEnd.RelationshipMultiplicity
                    = redundantAssociation.TargetEnd.RelationshipMultiplicity;

                if (redundantAssociation.Constraint != null)
                {
                    unifiedAssociation.Constraint = redundantAssociation.Constraint;
                    unifiedAssociation.Constraint.DependentEnd =
                        unifiedAssociation.Constraint.DependentEnd.GetEntityType() == unifiedAssociation.SourceEnd.GetEntityType()
                            ? unifiedAssociation.SourceEnd
                            : unifiedAssociation.TargetEnd;
                }

                FixNavigationProperties(model, unifiedAssociation, redundantAssociation);

                model.RemoveAssociationType(redundantAssociation);
            }
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:52,代码来源:AssociationInverseDiscoveryConvention.cs

示例2: 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();
            associationType.SourceEnd = new AssociationEndMember("S", new EntityType());
            associationType.TargetEnd = new AssociationEndMember("T", new EntityType());
            var inverseAssociationType = new AssociationType();
            inverseAssociationType.SourceEnd = new AssociationEndMember("S", new EntityType());
            inverseAssociationType.TargetEnd = new AssociationEndMember("T", new EntityType());
            var model = new EdmModel().Initialize();
            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.Equal(0, model.GetAssociationTypes().Count());
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:30,代码来源:NavigationPropertyConfigurationTests.cs


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