private static void AddReferenceKeyColumns(List <EntityDataSourceColumn> columns, MetadataWorkspace ocWorkspace, EntitySet entitySet, EntityType entityType, Dictionary <EdmProperty, EntityDataSourcePropertyColumn> entityProperties) { foreach (AssociationSetEnd toEnd in GetReferenceEnds(entitySet, entityType, /*forKey*/ true)) { ReferentialConstraint constraint; bool isContained = EntityDataSourceUtil.IsContained(toEnd, out constraint); // Create a group for the end columns EntityType toType = EntityDataSourceUtil.GetEntityType(toEnd); Type clrToType = EntityDataSourceUtil.GetClrType(ocWorkspace, toType); EntityDataSourceReferenceGroup group = EntityDataSourceReferenceGroup.Create(clrToType, toEnd); // Create a column for every key foreach (EdmProperty keyMember in GetEntityType(toEnd).KeyMembers) { EntityDataSourceColumn controllingColumn = null; if (isContained) { // if this key is 'contained' in the entity, make the referential constrained // property the principal for the column int ordinalInConstraint = constraint.FromProperties.IndexOf(keyMember); // find corresponding member in the current (dependent) entity EdmProperty correspondingProperty = constraint.ToProperties[ordinalInConstraint]; controllingColumn = entityProperties[correspondingProperty]; } columns.Add(new EntityDataSourceReferenceKeyColumn(ocWorkspace, group, keyMember, controllingColumn)); } } }
internal EntityDataSourceReferenceKeyColumn(MetadataWorkspace workspace, EntityDataSourceReferenceGroup group, EdmProperty keyMember, EntityDataSourceColumn dependent) : base(CreateDisplayName(group, keyMember), dependent) { EntityDataSourceUtil.CheckArgumentNull(group, "group"); EntityDataSourceUtil.CheckArgumentNull(keyMember, "keyMember"); Debug.Assert(EntityDataSourceUtil.IsScalar(keyMember.TypeUsage.EdmType), "Expected primitive or enum type for key members."); this.group = group; this.keyMember = keyMember; this.clrType = EntityDataSourceUtil.GetMemberClrType(workspace, keyMember); // if the association end is optional (0..1), make sure the CLR type // is also nullable if (this.group.End.CorrespondingAssociationEndMember.RelationshipMultiplicity == RelationshipMultiplicity.ZeroOrOne) { this.clrType = EntityDataSourceUtil.MakeNullable(clrType); this.isNullable = true; } }
private static string CreateDisplayName(EntityDataSourceReferenceGroup group, EdmProperty keyMember) { EntityDataSourceUtil.CheckArgumentNull(group, "group"); EntityDataSourceUtil.CheckArgumentNull(keyMember, "keyMember"); NavigationProperty navigationProperty; string result; if (EntityDataSourceUtil.TryGetCorrespondingNavigationProperty(group.End.CorrespondingAssociationEndMember, out navigationProperty)) { result = navigationProperty.Name + "." + keyMember.Name; } else { // if there is no Navigation property, use the TargetTole and KeyMember name // TargetRole.KeyMember result = group.End.Name + "." + keyMember.Name; } return(result); }
private static string CreateDisplayName(EntityDataSourceReferenceGroup group, EdmProperty keyMember) { EntityDataSourceUtil.CheckArgumentNull(group, "group"); EntityDataSourceUtil.CheckArgumentNull(keyMember, "keyMember"); NavigationProperty navigationProperty; string result; if (EntityDataSourceUtil.TryGetCorrespondingNavigationProperty(group.End.CorrespondingAssociationEndMember, out navigationProperty)) { result = navigationProperty.Name + "." + keyMember.Name; } else { // if there is no Navigation property, use the TargetTole and KeyMember name // TargetRole.KeyMember result = group.End.Name + "." + keyMember.Name; } return result; }