本文整理汇总了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;
}