diff --git a/src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataResourceSerializer.cs b/src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataResourceSerializer.cs
index 1811ae9dfd..306856234f 100644
--- a/src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataResourceSerializer.cs
+++ b/src/Microsoft.AspNet.OData.Shared/Formatter/Serialization/ODataResourceSerializer.cs
@@ -343,7 +343,7 @@ internal async Task WriteDeltaComplexPropertiesAsync(SelectExpandNode selectExpa
}
private void WriteDeltaComplexAndExpandedNavigationProperty(IEdmProperty edmProperty, SelectExpandClause selectExpandClause,
- ResourceContext resourceContext, ODataWriter writer, Type type = null)
+ ResourceContext resourceContext, ODataWriter writer, Type navigationPropertyType = null)
{
Contract.Assert(edmProperty != null);
Contract.Assert(resourceContext != null);
@@ -376,7 +376,7 @@ private void WriteDeltaComplexAndExpandedNavigationProperty(IEdmProperty edmProp
{
// create the serializer context for the complex and expanded item.
ODataSerializerContext nestedWriteContext = new ODataSerializerContext(resourceContext, selectExpandClause, edmProperty);
- nestedWriteContext.Type = type;
+ nestedWriteContext.Type = navigationPropertyType;
// write object.
@@ -401,7 +401,7 @@ private void WriteDeltaComplexAndExpandedNavigationProperty(IEdmProperty edmProp
}
private async Task WriteDeltaComplexAndExpandedNavigationPropertyAsync(IEdmProperty edmProperty, SelectExpandClause selectExpandClause,
- ResourceContext resourceContext, ODataWriter writer, Type type = null)
+ ResourceContext resourceContext, ODataWriter writer, Type navigationPropertyType = null)
{
Contract.Assert(edmProperty != null);
Contract.Assert(resourceContext != null);
@@ -434,7 +434,7 @@ await writer.WriteStartAsync(new ODataResourceSet
{
// create the serializer context for the complex and expanded item.
ODataSerializerContext nestedWriteContext = new ODataSerializerContext(resourceContext, selectExpandClause, edmProperty);
- nestedWriteContext.Type = type;
+ nestedWriteContext.Type = navigationPropertyType;
// write object.
@@ -648,7 +648,6 @@ private void WriteResource(object graph, ODataWriter writer, ODataSerializerCont
WriteDynamicComplexProperties(resourceContext, writer);
WriteNavigationLinks(selectExpandNode, resourceContext, writer);
WriteExpandedNavigationProperties(selectExpandNode, resourceContext, writer);
- WriteNestedNavigationProperties(selectExpandNode, resourceContext, writer);
WriteReferencedNavigationProperties(selectExpandNode, resourceContext, writer);
writer.WriteEnd();
}
@@ -691,7 +690,6 @@ await writer.WriteEntityReferenceLinkAsync(new ODataEntityReferenceLink
await WriteDynamicComplexPropertiesAsync(resourceContext, writer);
await WriteNavigationLinksAsync(selectExpandNode, resourceContext, writer);
await WriteExpandedNavigationPropertiesAsync(selectExpandNode, resourceContext, writer);
- await WriteNestedNavigationPropertiesAsync(selectExpandNode, resourceContext, writer);
await WriteReferencedNavigationPropertiesAsync(selectExpandNode, resourceContext, writer);
await writer.WriteEndAsync();
}
@@ -737,12 +735,12 @@ public virtual SelectExpandNode CreateSelectExpandNode(ResourceContext resourceC
/// The created .
public virtual ODataResource CreateResource(SelectExpandNode selectExpandNode, ResourceContext resourceContext)
{
- ODataResource resource = CreateResourceBase(selectExpandNode, resourceContext, false) as ODataResource;
+ ODataResource resource = CreateResource(selectExpandNode, resourceContext, false) as ODataResource;
return resource;
}
- private ODataResourceBase CreateResourceBase(SelectExpandNode selectExpandNode, ResourceContext resourceContext, bool isDeletedResource)
+ private ODataResourceBase CreateResource(SelectExpandNode selectExpandNode, ResourceContext resourceContext, bool isDeletedResource)
{
if (selectExpandNode == null)
{
@@ -880,7 +878,7 @@ private ODataResourceBase CreateResourceBase(SelectExpandNode selectExpandNode,
/// The created .
public virtual ODataDeletedResource CreateDeletedResource(SelectExpandNode selectExpandNode, ResourceContext resourceContext)
{
- ODataDeletedResource resource = CreateResourceBase(selectExpandNode, resourceContext, true) as ODataDeletedResource;
+ ODataDeletedResource resource = CreateResource(selectExpandNode, resourceContext, true) as ODataDeletedResource;
return resource;
}
@@ -1121,7 +1119,7 @@ private void WriteNavigationLinks(SelectExpandNode selectExpandNode, ResourceCon
Contract.Assert(selectExpandNode != null);
Contract.Assert(resourceContext != null);
- if (selectExpandNode.SelectedNavigationProperties == null || resourceContext.IsPostRequest)
+ if (selectExpandNode.SelectedNavigationProperties == null)
{
return;
}
@@ -1142,7 +1140,7 @@ private async Task WriteNavigationLinksAsync(SelectExpandNode selectExpandNode,
Contract.Assert(selectExpandNode != null);
Contract.Assert(resourceContext != null);
- if (selectExpandNode.SelectedNavigationProperties == null || resourceContext.IsPostRequest)
+ if (selectExpandNode.SelectedNavigationProperties == null)
{
return;
}
@@ -1390,6 +1388,18 @@ private IEnumerable> GetPro
{
if (changedProperties == null || changedProperties.Contains(complexProperty.Key.Name))
{
+ IEdmTypeReference type = complexProperty.Key == null ? null : complexProperty.Key.Type;
+
+ if (type != null && resourceContext.EdmModel != null)
+ {
+ Type clrType = EdmLibHelpers.GetClrType(type.AsStructured(), resourceContext.EdmModel);
+
+ if (clrType != null && clrType == typeof(ODataIdContainer))
+ {
+ continue;
+ }
+ }
+
yield return complexProperty;
}
}
@@ -1435,32 +1445,6 @@ private IEnumerable> GetNavigationPro
}
}
}
- // Serializing nested navigation properties from a deep insert request.
- // We currently don't deserialize Deep insert nested resources as Delta but as T. If this was to change in the future, logic in this method will have to change.
- else if (resourceContext.IsPostRequest)
- {
- object instance = resourceContext.ResourceInstance;
- PropertyInfo[] properties = instance.GetType().GetProperties();
- Dictionary propertyNamesAndValues = new Dictionary();
-
- foreach (PropertyInfo propertyInfo in properties)
- {
- string name = propertyInfo.Name;
- object value = propertyInfo.GetValue(instance);
- propertyNamesAndValues.Add(name, value);
- }
-
- foreach (IEdmNavigationProperty navigationProperty in navigationProperties)
- {
- if (propertyNamesAndValues.TryGetValue(navigationProperty.Name, out object obj))
- {
- if (obj != null)
- {
- yield return new KeyValuePair(navigationProperty, obj.GetType());
- }
- }
- }
- }
}
private void WriteExpandedNavigationProperties(SelectExpandNode selectExpandNode, ResourceContext resourceContext, ODataWriter writer)
@@ -1653,58 +1637,6 @@ await writer.WriteStartAsync(new ODataResourceSet
}
}
- private void WriteNestedNavigationProperties(SelectExpandNode selectExpandNode, ResourceContext resourceContext, ODataWriter writer)
- {
- Debug.Assert(resourceContext != null, "resourceContext != null");
- Debug.Assert(writer != null, "writer != null");
-
- if (!resourceContext.IsPostRequest)
- {
- return;
- }
-
- IEnumerable> navigationProperties = GetNavigationPropertiesToWrite(selectExpandNode, resourceContext);
-
- foreach (KeyValuePair navigationProperty in navigationProperties)
- {
- ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo
- {
- IsCollection = navigationProperty.Key.Type.IsCollection(),
- Name = navigationProperty.Key.Name
- };
-
- writer.WriteStart(nestedResourceInfo);
- WriteComplexAndExpandedNavigationProperty(navigationProperty.Key, null, resourceContext, writer);
- writer.WriteEnd();
- }
- }
-
- private async Task WriteNestedNavigationPropertiesAsync(SelectExpandNode selectExpandNode, ResourceContext resourceContext, ODataWriter writer)
- {
- Debug.Assert(resourceContext != null, "resourceContext != null");
- Debug.Assert(writer != null, "writer != null");
-
- if (!resourceContext.IsPostRequest)
- {
- return;
- }
-
- IEnumerable> navigationProperties = GetNavigationPropertiesToWrite(selectExpandNode, resourceContext);
-
- foreach (KeyValuePair navigationProperty in navigationProperties)
- {
- ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo
- {
- IsCollection = navigationProperty.Key.Type.IsCollection(),
- Name = navigationProperty.Key.Name
- };
-
- await writer.WriteStartAsync(nestedResourceInfo);
- await WriteComplexAndExpandedNavigationPropertyAsync(navigationProperty.Key, null, resourceContext, writer);
- await writer.WriteEndAsync();
- }
- }
-
private IEnumerable CreateNavigationLinks(
IEnumerable navigationProperties, ResourceContext resourceContext)
{
diff --git a/src/Microsoft.AspNet.OData.Shared/ResourceContext.cs b/src/Microsoft.AspNet.OData.Shared/ResourceContext.cs
index c03cebfab4..b2540fc687 100644
--- a/src/Microsoft.AspNet.OData.Shared/ResourceContext.cs
+++ b/src/Microsoft.AspNet.OData.Shared/ResourceContext.cs
@@ -96,18 +96,6 @@ public IEdmModel EdmModel
}
}
- internal bool IsPostRequest
- {
- get
- {
-#if NETCORE
- return Request == null ? false : String.Equals(Request.Method, "post", StringComparison.OrdinalIgnoreCase);
-#else
- return Request == null ? false : Request.Method == HttpMethod.Post;
-#endif
- }
- }
-
///
/// Gets or sets the to which this instance belongs.
///