/// <summary>
        /// Converts the complex instance into an entity instance based on the metadata
        /// </summary>
        /// <param name="payloadElement">The payload element to potentially replace</param>
        /// <returns>The original element or a copy to replace it with</returns>
        public override ODataPayloadElement Visit(ComplexInstance payloadElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");
            if (payloadElement.Annotations.OfType<EntitySetAnnotation>().Any())
            {
                var entityInstance = new EntityInstance(payloadElement.FullTypeName, payloadElement.IsNull);
                entityInstance.Properties = this.VisitCollection(payloadElement.Properties);
                return payloadElement.ReplaceWith(entityInstance);
            }

            return base.Visit(payloadElement);
        }
        /// <summary>
        /// Converts the complex instance into an entity instance based on the metadata
        /// </summary>
        /// <param name="payloadElement">The payload element to potentially replace</param>
        /// <returns>The original element or a copy to replace it with</returns>
        public override ODataPayloadElement Visit(ComplexInstance payloadElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");
            if (payloadElement.Annotations.OfType <EntitySetAnnotation>().Any())
            {
                var entityInstance = new EntityInstance(payloadElement.FullTypeName, payloadElement.IsNull);
                entityInstance.Properties = this.VisitCollection(payloadElement.Properties);
                return(payloadElement.ReplaceWith(entityInstance));
            }

            return(base.Visit(payloadElement));
        }
Пример #3
0
        /// <summary>
        /// Visits the children of the given payload element and replaces it with a copy if any child changes
        /// </summary>
        /// <param name="payloadElement">The payload element to potentially replace</param>
        /// <returns>The original element or a copy to replace it with</returns>
        public virtual ODataPayloadElement Visit(ComplexInstance payloadElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");

            var replacedProperties = this.VisitCollection(payloadElement.Properties);

            if (!this.ShouldReplace(replacedProperties, payloadElement.Properties))
            {
                return(payloadElement);
            }

            var replacedInstance = payloadElement.ReplaceWith(new ComplexInstance(payloadElement.FullTypeName, payloadElement.IsNull));

            foreach (var property in replacedProperties)
            {
                replacedInstance.Add(property);
            }

            return(replacedInstance);
        }