コード例 #1
0
        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));
                }
            }
        }