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(); }