Ejemplo n.º 1
0
        private void ApplyNestedDeltaResourceSet(IEdmProperty nestedProperty, object resource,
                                                 ODataDeltaResourceSetWrapper deltaResourceSetWrapper, ODataDeserializerContext readContext)
        {
            Contract.Assert(nestedProperty != null);
            Contract.Assert(resource != null);
            Contract.Assert(readContext != null);

            IEdmTypeReference        edmType      = nestedProperty.Type;
            ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(edmType, true);

            if (deserializer == null)
            {
                throw new SerializationException(Error.Format(SRResources.TypeCannotBeDeserialized, edmType.FullName()));
            }

            IEdmStructuredTypeReference structuredType    = edmType.AsCollection().ElementType().AsStructured();
            ODataDeserializerContext    nestedReadContext = readContext.CloneWithoutType();

            if (readContext.IsNoClrType)
            {
                nestedReadContext.ResourceType = typeof(EdmChangedObjectCollection);
            }
            else
            {
                Type clrType = readContext.Model.GetClrType(structuredType);

                if (clrType == null)
                {
                    throw new ODataException(
                              Error.Format(SRResources.MappingDoesNotContainResourceType, structuredType.FullName()));
                }

                nestedReadContext.ResourceType = typeof(DeltaSet <>).MakeGenericType(clrType);
            }

            object value = deserializer.ReadInline(deltaResourceSetWrapper, edmType, nestedReadContext);

            string propertyName = readContext.Model.GetClrPropertyName(nestedProperty);

            DeserializationHelpers.SetCollectionProperty(resource, nestedProperty, value, propertyName);
        }
Ejemplo n.º 2
0
        private void ApplyResourceSetInNestedProperty(IEdmProperty nestedProperty, object resource,
                                                      ODataResourceSetWrapper resourceSetWrapper, ODataDeserializerContext readContext)
        {
            Contract.Assert(nestedProperty != null);
            Contract.Assert(resource != null);
            Contract.Assert(readContext != null);

            if (readContext.IsDeltaOfT)
            {
                IEdmNavigationProperty navigationProperty = nestedProperty as IEdmNavigationProperty;
                if (navigationProperty != null)
                {
                    string message = Error.Format(SRResources.CannotPatchNavigationProperties, navigationProperty.Name,
                                                  navigationProperty.DeclaringEntityType().FullName());
                    throw new ODataException(message);
                }
            }

            object value = ReadNestedResourceSetInline(resourceSetWrapper, nestedProperty.Type, readContext);

            string propertyName = readContext.Model.GetClrPropertyName(nestedProperty);

            DeserializationHelpers.SetCollectionProperty(resource, nestedProperty, value, propertyName);
        }