/// <summary> /// Verifies that CreateResourceReader, CreateResourceSetReader, CreateDeltaResourceSetReader or CreateDeltaReader can be called. /// </summary> /// <param name="navigationSource">The navigation source we are going to read resources for.</param> /// <param name="structuredType">The expected structured type for the resource/resource set to be read.</param> private void VerifyCanCreateODataReader(IEdmNavigationSource navigationSource, IEdmStructuredType structuredType) { Debug.Assert(navigationSource == null || structuredType != null, "If an navigation source is specified, the structured type must be specified as well."); // We require metadata information for reading requests. if (!this.ReadingResponse) { this.VerifyUserModel(); // TODO: check for entity only if (navigationSource == null && (structuredType != null && structuredType.IsODataEntityTypeKind())) { throw new ODataException(ODataErrorStrings.ODataJsonLightInputContext_NoEntitySetForRequest); } } // We only check that the base type of the entity set is assignable from the specified entity type. // If no resource set/resource type is specified in the API, we will read it from the context URI. IEdmEntityType entitySetElementType = this.EdmTypeResolver.GetElementType(navigationSource); if (navigationSource != null && structuredType != null && !structuredType.IsOrInheritsFrom(entitySetElementType)) { throw new ODataException(ODataErrorStrings.ODataJsonLightInputContext_EntityTypeMustBeCompatibleWithEntitySetBaseType(structuredType.FullTypeName(), entitySetElementType.FullName(), navigationSource.FullNavigationSourceName())); } }
/// <summary> /// Verifies that CreateEntryReader or CreateFeedReader or CreateDeltaReader can be called. /// </summary> /// <param name="navigationSource">The navigation source we are going to read entities for.</param> /// <param name="entityType">The expected entity type for the entry/entries to be read.</param> private void VerifyCanCreateODataReader(IEdmNavigationSource navigationSource, IEdmEntityType entityType) { Debug.Assert(navigationSource == null || entityType != null, "If an navigation source is specified, the entity type must be specified as well."); // We require metadata information for reading requests. if (!this.ReadingResponse) { this.VerifyUserModel(); if (navigationSource == null) { throw new ODataException(ODataErrorStrings.ODataJsonLightInputContext_NoEntitySetForRequest); } } // We only check that the base type of the entity set is assignable from the specified entity type. // If no entity set/entity type is specified in the API, we will read it from the context URI. IEdmEntityType entitySetElementType = this.EdmTypeResolver.GetElementType(navigationSource); if (navigationSource != null && entityType != null && !entityType.IsOrInheritsFrom(entitySetElementType)) { throw new ODataException(ODataErrorStrings.ODataJsonLightInputContext_EntityTypeMustBeCompatibleWithEntitySetBaseType(entityType.FullName(), entitySetElementType.FullName(), navigationSource.FullNavigationSourceName())); } }