/// <summary> /// Verifies that the query's typeusage will not result in a polymorphic result. /// If the query would be restricted "is of only" using entityTypeFilter, then /// this check assumes the result will not be polymorphic. /// /// This method is only called if the user specifies EntitySetName and updates are enabled. /// /// Does nothing for RowTypes. /// </summary> /// <param name="typeUsage">The TypeUsage from the query</param> /// <param name="itemCollection"></param> /// <returns></returns> internal static void CheckNonPolymorphicTypeUsage(EntityType entityType, ItemCollection ocItemCollection, string entityTypeFilter) { CheckArgumentNull <ItemCollection>(ocItemCollection, "ocItemCollection"); if (String.IsNullOrEmpty(entityTypeFilter)) { List <EdmType> types = new List <EdmType>(EntityDataSourceUtil.GetTypeAndSubtypesOf(entityType, ocItemCollection, /*includeAbstractTypes*/ true)); if (entityType.BaseType != null || types.Count() > 1 || entityType.Abstract) { throw new InvalidOperationException(Strings.EntityDataSourceUtil_EntityQueryCannotReturnPolymorphicTypes); } } return; }
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(); }