private static void WriteResource(ODataWriterWrapper writer, ODataResourceWrapper resourceWrapper) { if (resourceWrapper.Resource == null) { writer.WriteStartResource(resourceWrapper.Resource); } else { writer.WriteStart(resourceWrapper.Resource, resourceWrapper.Instance); } if (resourceWrapper.NestedResourceInfoWrappers != null) { foreach (var nestedResourceInfoWrapper in resourceWrapper.NestedResourceInfoWrappers) { WriteNestedResourceInfo(writer, nestedResourceInfoWrapper); } } if (resourceWrapper.Resource == null) { writer.WriteEnd(); } else { writer.WriteEnd(resourceWrapper.Resource, resourceWrapper.Instance); } }
private static void WriteResourceSet(ODataWriterWrapper writer, ODataResourceSetWrapper resourceSetWrapper) { writer.WriteStart(resourceSetWrapper.ResourceSet); if (resourceSetWrapper.Resources != null) { foreach (var resourceWrapper in resourceSetWrapper.Resources) { WriteResource(writer, resourceWrapper); } } writer.WriteEnd(); }
/// <summary> /// Write the entry element. /// </summary> /// <param name="entityDescriptor">The entity.</param> /// <param name="relatedLinks">Collection of links related to the entity.</param> /// <param name="requestMessage">The OData request message.</param> internal void WriteEntry(EntityDescriptor entityDescriptor, IEnumerable <LinkDescriptor> relatedLinks, ODataRequestMessageWrapper requestMessage) { ClientEdmModel model = this.requestInfo.Model; ClientTypeAnnotation entityType = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType())); using (ODataMessageWriter messageWriter = Serializer.CreateMessageWriter(requestMessage, this.requestInfo, false /*isParameterPayload*/)) { ODataWriterWrapper entryWriter = ODataWriterWrapper.CreateForEntry(messageWriter, this.requestInfo.Configurations.RequestPipeline); // Get the server type name using the type resolver or from the entity descriptor string serverTypeName = this.requestInfo.GetServerTypeName(entityDescriptor); var entry = CreateODataEntry(entityDescriptor, serverTypeName, entityType, this.requestInfo.Format); if (serverTypeName == null) { serverTypeName = this.requestInfo.InferServerTypeNameFromServerModel(entityDescriptor); } IEnumerable <ClientPropertyAnnotation> properties; if ((!Util.IsFlagSet(this.options, SaveChangesOptions.ReplaceOnUpdate) && entityDescriptor.State == EntityStates.Modified && entityDescriptor.PropertiesToSerialize.Any()) || (Util.IsFlagSet(this.options, SaveChangesOptions.PostOnlySetProperties) && entityDescriptor.State == EntityStates.Added)) { properties = entityType.PropertiesToSerialize().Where(prop => entityDescriptor.PropertiesToSerialize.Contains(prop.PropertyName)); } else { properties = entityType.PropertiesToSerialize(); } entry.Properties = this.propertyConverter.PopulateProperties(entityDescriptor.Entity, serverTypeName, properties); entryWriter.WriteStart(entry, entityDescriptor.Entity); this.WriteNestedComplexProperties(entityDescriptor.Entity, serverTypeName, properties, entryWriter); if (EntityStates.Added == entityDescriptor.State) { this.WriteNestedResourceInfo(entityDescriptor, relatedLinks, entryWriter); } entryWriter.WriteEnd(entry, entityDescriptor.Entity); } }