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 EntityDataSourceMemberPath(MetadataWorkspace ocWorkspace, EntityDataSourceMemberPath parent, EdmProperty property, bool isLocallyInteresting) { EntityDataSourceUtil.CheckArgumentNull(ocWorkspace, "ocWorkspace"); EntityDataSourceUtil.CheckArgumentNull(property, "property"); this.property = property; this.parent = parent; this.isLocallyInteresting = isLocallyInteresting; this.clrType = EntityDataSourceUtil.GetMemberClrType(ocWorkspace, property); this.isKey = IsPropertyAKey(property); // retrieve PropertyInfo (with respect to parent CLR type) StructuralType parentType = property.DeclaringType; Type parentClrType = EntityDataSourceUtil.GetClrType(ocWorkspace, parentType); this.propertyInfo = EntityDataSourceUtil.GetPropertyInfo(parentClrType, this.property.Name); }
internal EntityDataSourceWrapperCollection(ObjectContext context, EntitySet entitySet, EntityType restrictedEntityType) { EntityDataSourceUtil.CheckArgumentNull(context, "context"); EntityDataSourceUtil.CheckArgumentNull(entitySet, "entitySet"); _context = context; _wrapperList = new List <EntityDataSourceWrapper>(); // get handles on the relevant workspaces MetadataWorkspace csWorkspace = ((EntityConnection)context.Connection).GetMetadataWorkspace(); MetadataWorkspace ocWorkspace = context.MetadataWorkspace; // if no restricted type is given, we assume the entity set element type is exposed EntityType entityType = restrictedEntityType ?? entitySet.ElementType; _clrEntityType = EntityDataSourceUtil.GetClrType(ocWorkspace, entityType); // if no restricted type is given and the set is polymorphic, make the collection readonly if (null == restrictedEntityType && 1 < EntityDataSourceUtil.GetTypeAndSubtypesOf(entityType, csWorkspace.GetItemCollection(DataSpace.CSpace), true).Count()) { _isReadOnly = true; } // gather the properties ReadOnlyCollection <EntityDataSourceColumn> columns = EntityDataSourceUtil.GetNamedColumns(csWorkspace, ocWorkspace, entitySet, entityType); List <PropertyDescriptor> visiblePropertyDescriptors = new List <PropertyDescriptor>(columns.Count); List <EntityDataSourceWrapperPropertyDescriptor> propertyDescriptors = new List <EntityDataSourceWrapperPropertyDescriptor>(columns.Count); foreach (EntityDataSourceColumn column in columns) { var descriptor = new EntityDataSourceWrapperPropertyDescriptor(this, column); propertyDescriptors.Add(descriptor); // if the descriptor does not have a dependent, it is exposed to the user if (!descriptor.Column.IsHidden) { visiblePropertyDescriptors.Add(descriptor); } } _visiblePropertyDescriptors = new PropertyDescriptorCollection(visiblePropertyDescriptors.ToArray(), true); AllPropertyDescriptors = propertyDescriptors.AsReadOnly(); }