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


C# StoreItemCollection.GetAllAssociations方法代码示例

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


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

示例1: IsJoinTable

        // TODO: in order to properly identify this we may need to add custom annotations in the SSDL 
        /// <summary>
        ///     We can infer that something is a join table in the SSDL if:
        ///     1. There are two associations originating from it
        ///     2. The two ends on the table are *
        ///     3. The other ends on the associations are 1
        ///     4. The number of properties in the table is equal to the sum of all the key properties on the other ends of both associations
        ///     5. All properties in the table are key properties
        /// </summary>
        /// <param name="entityType">The EntityType to test.</param>
        /// <param name="store">The StoreItemCollection containing EntityType.</param>
        /// <returns>true if the specified EntityType is a join table; otherwise, false.</returns>
        public static bool IsJoinTable(this EntityType entityType, StoreItemCollection store)
        {
            var associations = store.GetAllAssociations().Where(a => a.IsAssociatedWithEntityType(entityType));
            if (associations.Count() == 2)
            {
                var sumOfAllKeyProperties = 0;
                var numEndsWithOneMultiplicity = 0;
                foreach (AssociationType association in associations)
                {
                    AssociationEndMember end1 = association.GetEnd1();
                    AssociationEndMember end2 = association.GetEnd2();
                    if ((end1.GetEntityType() == entityType)
                        && (end1.RelationshipMultiplicity == RelationshipMultiplicity.Many)
                        && (end2.RelationshipMultiplicity == RelationshipMultiplicity.One))
                    {
                        sumOfAllKeyProperties += end2.GetEntityType().GetKeyProperties().Count();
                        numEndsWithOneMultiplicity++;
                    }
                    else if ((end2.GetEntityType() == entityType)
                             && (end2.RelationshipMultiplicity == RelationshipMultiplicity.Many)
                             && (end1.RelationshipMultiplicity == RelationshipMultiplicity.One))
                    {
                        sumOfAllKeyProperties += end1.GetEntityType().GetKeyProperties().Count();
                        numEndsWithOneMultiplicity++;
                    }
                }

                int intersectCount = entityType.GetKeyProperties().Intersect(entityType.Properties).Count();

                if (numEndsWithOneMultiplicity == 2
                    && entityType.GetKeyProperties().Count() == sumOfAllKeyProperties
                    && entityType.GetKeyProperties().Count() == intersectCount
                    && entityType.Properties.Count == intersectCount)
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:52,代码来源:MetadataWorkspaceExtensions.cs


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