private bool TryProcessDeltaNestedResourceSet(IEdmProperty collectionProperty, object resource, ODataResourceSetWrapper resourceSetWrapper, ODataDeserializerContext readContext) { string collectionPropertyName = EdmLibHelpers.GetClrPropertyName(collectionProperty, readContext.Model); IDelta resourceDelta = resource as IDelta; if (resourceDelta == null) { return(false); } if (resourceSetWrapper == null) { return(resourceDelta.TrySetPropertyReferencedValue(collectionPropertyName, null)); } if (resourceSetWrapper.Resources == null) { return(false); } IEdmStructuredTypeReference structuredElementType = collectionProperty.Type.AsCollection().ElementType().AsStructured(); Type clrElementType = EdmLibHelpers.GetClrType(structuredElementType, readContext.Model); Type deltaType = typeof(Delta <>).MakeGenericType(clrElementType); IEnumerable <string> structuralProperties = GetUpdatableProperties(readContext.Model, structuredElementType); IList elementDeltas = new ArrayList(); foreach (ODataResourceWrapper resourceWrapper in resourceSetWrapper.Resources) { Delta elementDelta = (Delta)Activator.CreateInstance(deltaType, clrElementType, structuralProperties); ApplyResourceProperties(elementDelta, resourceWrapper, structuredElementType, readContext); elementDeltas.Add(elementDelta); } return(resourceDelta.TrySetPropertyCollectionValue(collectionPropertyName, elementDeltas)); }
private void ApplyDeltaResourceSetInNestedProperty(IEdmProperty nestedProperty, object resource, ODataDeltaResourceSetWrapper resourceSetWrapper, ODataDeserializerContext readContext) { Contract.Assert(nestedProperty != null); Contract.Assert(resource != null); Contract.Assert(readContext != null); if (!readContext.IsDeltaOfT) { throw new ODataException("Read context of @odata.delta incorrect"); } ICollection modifiedItems; ICollection deletedItems; ReadDeltaResourceSetInline(resourceSetWrapper, nestedProperty.Type, readContext, out modifiedItems, out deletedItems); IDelta resourceDelta = (IDelta)resource; string propertyName = EdmLibHelpers.GetClrPropertyName(nestedProperty, readContext.Model); resourceDelta.TrySetPropertyCollectionValue(propertyName, modifiedItems); resourceDelta.TrySetDeletedPropertyValue(propertyName, deletedItems); }