/// <summary> /// Deserializes the given <paramref name="entryWrapper"/> under the given <paramref name="readContext"/>. /// </summary> /// <param name="entryWrapper">The OData entry to deserialize.</param> /// <param name="entityType">The entity type of the entry to deserialize.</param> /// <param name="readContext">The deserializer context.</param> /// <returns>The deserialized entity.</returns> public virtual object ReadEntry(ODataEntryWithNavigationLinks entryWrapper, IEdmEntityTypeReference entityType, ODataDeserializerContext readContext) { if (entryWrapper == null) { throw Error.ArgumentNull("entryWrapper"); } if (readContext == null) { throw Error.ArgumentNull("readContext"); } if (!String.IsNullOrEmpty(entryWrapper.Entry.TypeName) && entityType.FullName() != entryWrapper.Entry.TypeName) { // received a derived type in a base type deserializer. delegate it to the appropriate derived type deserializer. IEdmModel model = readContext.Model; if (model == null) { throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext); } IEdmEntityType actualType = model.FindType(entryWrapper.Entry.TypeName) as IEdmEntityType; if (actualType == null) { throw new ODataException(Error.Format(SRResources.EntityTypeNotInModel, entryWrapper.Entry.TypeName)); } if (actualType.IsAbstract) { string message = Error.Format(SRResources.CannotInstantiateAbstractEntityType, entryWrapper.Entry.TypeName); throw new ODataException(message); } IEdmTypeReference actualEntityType = new EdmEntityTypeReference(actualType, isNullable: false); ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(actualEntityType); if (deserializer == null) { throw new SerializationException( Error.Format(SRResources.TypeCannotBeDeserialized, actualEntityType.FullName(), typeof(ODataMediaTypeFormatter).Name)); } object resource = deserializer.ReadInline(entryWrapper, actualEntityType, readContext); EdmStructuredObject structuredObject = resource as EdmStructuredObject; if (structuredObject != null) { structuredObject.ExpectedEdmType = entityType.EntityDefinition(); } return resource; } else { object resource = CreateEntityResource(entityType, readContext); ApplyEntityProperties(resource, entryWrapper, entityType, readContext); return resource; } }
public void Named_type_reference_fullName_returns_fullName() { IEdmModel edmModel = this.GetEdmModel(); foreach (var entity in edmModel.SchemaElements.OfType<IEdmEntityType>()) { var entityTypeRef = new EdmEntityTypeReference(entity, false); Assert.IsNotNull(entityTypeRef.FullName(), "EntityTypeReference.FullName()"); Assert.AreEqual(entity.FullName(), entityTypeRef.FullName(), "EntityTypeReference.FullName()"); } foreach (var complex in edmModel.SchemaElements.OfType<IEdmComplexType>()) { var complexTypeRef = new EdmComplexTypeReference(complex, false); Assert.IsNotNull(complexTypeRef.FullName(), "ComplexTypeReference.FullName()"); Assert.AreEqual(complex.FullName(), complexTypeRef.FullName(), "ComplexTypeReference.FullName()"); } }