Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ internal static async Task WriteToStreamAsync(
writeContext.QueryOptions = queryOptions;
writeContext.SetComputedProperties(queryOptions?.Compute?.ComputeClause);
writeContext.Type = type;
writeContext.IsDelta = serializer.ODataPayloadKind == ODataPayloadKind.Delta;

//Set the SelectExpandClause on the context if it was explicitly specified.
if (selectExpandDifferentFromQueryOptions != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private async Task WriteDeltaComplexPropertiesAsync(SelectExpandNode selectExpan

IEnumerable<IEdmStructuralProperty> complexProperties = selectExpandNode.SelectedComplexProperties.Keys;

if (null != resourceContext.EdmObject && resourceContext.EdmObject.IsDeltaResource())
if (resourceContext.EdmObject != null && resourceContext.SerializerContext.IsDelta)
{
IDelta deltaObject = null;
if (resourceContext.EdmObject is TypedEdmEntityObject obj)
Expand Down Expand Up @@ -477,7 +477,7 @@ private async Task WriteResourceAsync(object graph, ODataWriter writer, ODataSer
}

await writer.WriteStartAsync(odataDeletedResource).ConfigureAwait(false);
await WriteResourceContent(writer, selectExpandNode, resourceContext, /*isDelta*/ true).ConfigureAwait(false);
await WriteResourceContent(writer, selectExpandNode, resourceContext).ConfigureAwait(false);
await writer.WriteEndAsync().ConfigureAwait(false);
}
else
Expand All @@ -494,9 +494,8 @@ await writer.WriteEntityReferenceLinkAsync(new ODataEntityReferenceLink
}
else
{
bool isDelta = graph is IDelta || graph is IEdmChangedObject;
await writer.WriteStartAsync(resource).ConfigureAwait(false);
await WriteResourceContent(writer, selectExpandNode, resourceContext, isDelta).ConfigureAwait(false);
await WriteResourceContent(writer, selectExpandNode, resourceContext).ConfigureAwait(false);
await writer.WriteEndAsync().ConfigureAwait(false);
}
}
Expand All @@ -512,11 +511,10 @@ await writer.WriteEntityReferenceLinkAsync(new ODataEntityReferenceLink
/// <param name="writer">The <see cref="ODataWriter" /> to use to write the resource contents</param>
/// <param name="selectExpandNode">The <see cref="SelectExpandNode"/> describing the response graph.</param>
/// <param name="resourceContext">The context for the resource instance being written.</param>
/// <param name="isDelta">Whether to only write changed properties of the resource</param>
private async Task WriteResourceContent(ODataWriter writer, SelectExpandNode selectExpandNode, ResourceContext resourceContext, bool isDelta)
private async Task WriteResourceContent(ODataWriter writer, SelectExpandNode selectExpandNode, ResourceContext resourceContext)
{
// TODO: These should be aligned; do we need different methods for delta versus non-delta complex/navigation properties?
if (isDelta)
if (resourceContext.SerializerContext.IsDelta)
{
await WriteUntypedPropertiesAsync(selectExpandNode, resourceContext, writer).ConfigureAwait(false);
await WriteStreamPropertiesAsync(selectExpandNode, resourceContext, writer).ConfigureAwait(false);
Expand Down Expand Up @@ -1130,7 +1128,7 @@ private async Task WriteComplexPropertiesAsync(SelectExpandNode selectExpandNode
return;
}

if (null != resourceContext.EdmObject && resourceContext.EdmObject.IsDeltaResource())
if (resourceContext.EdmObject != null && resourceContext.SerializerContext.IsDelta)
{
IDelta deltaObject = resourceContext.EdmObject as IDelta;
IEnumerable<string> changedProperties = deltaObject.GetChangedPropertyNames();
Expand Down Expand Up @@ -1400,7 +1398,7 @@ private IEnumerable<ODataProperty> CreateStructuralPropertyBag(SelectExpandNode
{
IEnumerable<IEdmStructuralProperty> structuralProperties = selectExpandNode.SelectedStructuralProperties;

if (null != resourceContext.EdmObject && resourceContext.EdmObject.IsDeltaResource())
if (resourceContext.EdmObject != null && resourceContext.SerializerContext.IsDelta)
{
IDelta deltaObject = null;
if (resourceContext.EdmObject is TypedEdmEntityObject obj)
Expand All @@ -1412,8 +1410,8 @@ private IEnumerable<ODataProperty> CreateStructuralPropertyBag(SelectExpandNode
deltaObject = resourceContext.EdmObject as IDelta;
}

if(deltaObject != null)
{
if (deltaObject != null)
{
IEnumerable<string> changedProperties = deltaObject.GetChangedPropertyNames();
structuralProperties = structuralProperties.Where(p => changedProperties.Contains(p.Name) || p.IsKey());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ public ODataSerializerContext()
/// <summary>
/// Initializes a new instance of the <see cref="ODataSerializerContext"/> class.
/// </summary>
/// <param name="resource">The resource whose property is being nested.</param>
/// <param name="resource">The context for the resource instance being written</param>
/// <param name="selectExpandClause">The <see cref="SelectExpandClause"/> for the property being nested.</param>
/// <param name="edmProperty">The complex property being nested or the navigation property being expanded.
/// If the resource property is the dynamic complex, the resource property is null.
/// </param>
/// <remarks>This constructor is used to construct the serializer context for writing nested and expanded properties.</remarks>
// TODO: Rename "resource" to "resourceContext" in next major release.
public ODataSerializerContext(ResourceContext resource, SelectExpandClause selectExpandClause, IEdmProperty edmProperty)
: this(resource, edmProperty, null, null)
{
Expand All @@ -59,22 +60,22 @@ public ODataSerializerContext(ResourceContext resource, SelectExpandClause selec
/// <summary>
/// Initializes a new instance of the <see cref="ODataSerializerContext"/> class for nested resources.
/// </summary>
/// <param name="resource">The resource whose property is being nested.</param>
/// <param name="resourceContext">The context for the resource instance being written.</param>
/// <param name="edmProperty">The complex property being nested or the navigation property being expanded.
/// If the resource property is the dynamic complex, the resource property is null.
/// </param>
/// <param name="queryContext">The <see cref="ODataQueryContext"/> for the property being nested.</param>
/// <param name="currentSelectItem">The <see cref="SelectItem"/> for the property being nested.></param>
internal ODataSerializerContext(ResourceContext resource, IEdmProperty edmProperty, ODataQueryContext queryContext, SelectItem currentSelectItem)
internal ODataSerializerContext(ResourceContext resourceContext, IEdmProperty edmProperty, ODataQueryContext queryContext, SelectItem currentSelectItem)
{
if (resource == null)
if (resourceContext == null)
{
throw Error.ArgumentNull("resource");
throw Error.ArgumentNull($"{nameof(resourceContext)}");
}

// Clone the resource's context. Use a helper function so it can
// handle platform-specific differences in ODataSerializerContext.
ODataSerializerContext context = resource.SerializerContext;
ODataSerializerContext context = resourceContext.SerializerContext;
this.Request = context.Request;

Model = context.Model;
Expand All @@ -89,7 +90,8 @@ internal ODataSerializerContext(ResourceContext resource, IEdmProperty edmProper

QueryContext = queryContext;

ExpandedResource = resource; // parent resource
ExpandedResource = resourceContext; // parent resource
IsDelta = context.IsDelta;

CurrentSelectItem = currentSelectItem;

Expand All @@ -107,7 +109,7 @@ internal ODataSerializerContext(ResourceContext resource, IEdmProperty edmProper
if (pathSelectItem != null)
{
SelectExpandClause = pathSelectItem.SelectAndExpand;
NavigationSource = resource.NavigationSource; // Use it's parent navigation source.
NavigationSource = resourceContext.NavigationSource; // Use it's parent navigation source.

SetComputedProperties(pathSelectItem.ComputeOption);
}
Expand All @@ -133,7 +135,7 @@ internal ODataSerializerContext(ResourceContext resource, IEdmProperty edmProper
}
else
{
NavigationSource = resource.NavigationSource;
NavigationSource = resourceContext.NavigationSource;
}
}
}
Expand Down Expand Up @@ -324,6 +326,11 @@ internal bool IsDeltaOfT
}
}

/// <summary>
/// Gets or sets a value indicating whether a delta payload is being serialized.
/// </summary>
internal bool IsDelta { get; set; }

/// <summary>
/// Gets or sets the <see cref="ExpandedNavigationSelectItem"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------------
// <copyright file="EdmEntityCollectionObject.cs" company=".NET Foundation">
// <copyright file="EdmEntityObjectCollection.cs" company=".NET Foundation">
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
// See License.txt in the project root for license information.
// </copyright>
Expand Down
54 changes: 29 additions & 25 deletions src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4792,14 +4792,13 @@
<param name="writer">The ODataWriter.</param>
<returns>A task that represents the asynchronous write operation</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteResourceContent(Microsoft.OData.ODataWriter,Microsoft.AspNetCore.OData.Formatter.Serialization.SelectExpandNode,Microsoft.AspNetCore.OData.Formatter.ResourceContext,System.Boolean)">
<member name="M:Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteResourceContent(Microsoft.OData.ODataWriter,Microsoft.AspNetCore.OData.Formatter.Serialization.SelectExpandNode,Microsoft.AspNetCore.OData.Formatter.ResourceContext)">
<summary>
Writes the context of a Resource
</summary>
<param name="writer">The <see cref="T:Microsoft.OData.ODataWriter" /> to use to write the resource contents</param>
<param name="selectExpandNode">The <see cref="T:Microsoft.AspNetCore.OData.Formatter.Serialization.SelectExpandNode"/> describing the response graph.</param>
<param name="resourceContext">The context for the resource instance being written.</param>
<param name="isDelta">Whether to only write changed properties of the resource</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.CreateSelectExpandNode(Microsoft.AspNetCore.OData.Formatter.ResourceContext)">
<summary>
Expand Down Expand Up @@ -5124,7 +5123,7 @@
<summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext"/> class.
</summary>
<param name="resource">The resource whose property is being nested.</param>
<param name="resource">The context for the resource instance being written</param>
<param name="selectExpandClause">The <see cref="P:Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.SelectExpandClause"/> for the property being nested.</param>
<param name="edmProperty">The complex property being nested or the navigation property being expanded.
If the resource property is the dynamic complex, the resource property is null.
Expand All @@ -5135,7 +5134,7 @@
<summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext"/> class for nested resources.
</summary>
<param name="resource">The resource whose property is being nested.</param>
<param name="resourceContext">The context for the resource instance being written.</param>
<param name="edmProperty">The complex property being nested or the navigation property being expanded.
If the resource property is the dynamic complex, the resource property is null.
</param>
Expand Down Expand Up @@ -5233,6 +5232,11 @@
Gets or sets the <see cref="P:Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.SelectExpandClause"/>.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.IsDelta">
<summary>
Gets or sets a value indicating whether a delta payload is being serialized.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.CurrentExpandedSelectItem">
<summary>
Gets or sets the <see cref="T:Microsoft.OData.UriParser.ExpandedNavigationSelectItem"/>.
Expand Down Expand Up @@ -5757,27 +5761,6 @@
Returning DeltaKind of the object within DeltaResourceSet payload
</summary>
</member>
<member name="T:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection">
<summary>
Represents an <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.IEdmObject"/> that is a collection of <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.IEdmEntityObject"/>s.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection.#ctor(Microsoft.OData.Edm.IEdmCollectionTypeReference)">
<summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection"/> class.
</summary>
<param name="edmType">The edm type of the collection.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection.#ctor(Microsoft.OData.Edm.IEdmCollectionTypeReference,System.Collections.Generic.IList{Microsoft.AspNetCore.OData.Formatter.Value.IEdmEntityObject})">
<summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection"/> class.
</summary>
<param name="edmType">The edm type of the collection.</param>
<param name="list">The list that is wrapped by the new collection.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection.GetEdmType">
<inheritdoc/>
</member>
<member name="T:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObject">
<summary>
Represents an <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.IEdmEntityObject"/> with no backing CLR <see cref="T:System.Type"/>.
Expand All @@ -5802,6 +5785,27 @@
<param name="edmType">The <see cref="T:Microsoft.OData.Edm.IEdmEntityType"/> of this object.</param>
<param name="isNullable">true if this object can be nullable; otherwise, false.</param>
</member>
<member name="T:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection">
<summary>
Represents an <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.IEdmObject"/> that is a collection of <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.IEdmEntityObject"/>s.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection.#ctor(Microsoft.OData.Edm.IEdmCollectionTypeReference)">
<summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection"/> class.
</summary>
<param name="edmType">The edm type of the collection.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection.#ctor(Microsoft.OData.Edm.IEdmCollectionTypeReference,System.Collections.Generic.IList{Microsoft.AspNetCore.OData.Formatter.Value.IEdmEntityObject})">
<summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection"/> class.
</summary>
<param name="edmType">The edm type of the collection.</param>
<param name="list">The list that is wrapped by the new collection.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Formatter.Value.EdmEntityObjectCollection.GetEdmType">
<inheritdoc/>
</member>
<member name="T:Microsoft.AspNetCore.OData.Formatter.Value.EdmEnumObject">
<summary>
Represents an <see cref="T:Microsoft.AspNetCore.OData.Formatter.Value.IEdmEnumObject"/> with no backing CLR <see cref="T:System.Type"/>.
Expand Down
2 changes: 0 additions & 2 deletions src/Microsoft.AspNetCore.OData/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.Naviga
Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.NavigationSource.get -> Microsoft.OData.Edm.IEdmNavigationSource
Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.NavigationSource.set -> void
Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.ODataSerializerContext() -> void
Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.ODataSerializerContext(Microsoft.AspNetCore.OData.Formatter.ResourceContext resource, Microsoft.OData.UriParser.SelectExpandClause selectExpandClause, Microsoft.OData.Edm.IEdmProperty edmProperty) -> void
Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.Path.get -> Microsoft.OData.UriParser.ODataPath
Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.Path.set -> void
Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.QueryOptions.get -> Microsoft.AspNetCore.OData.Query.ODataQueryOptions
Expand Down Expand Up @@ -953,7 +952,6 @@ Microsoft.AspNetCore.OData.Query.HandleNullPropagationOption.False = 2 -> Micros
Microsoft.AspNetCore.OData.Query.HandleNullPropagationOption.True = 1 -> Microsoft.AspNetCore.OData.Query.HandleNullPropagationOption
Microsoft.AspNetCore.OData.Query.HttpRequestODataQueryExtensions
Microsoft.AspNetCore.OData.Query.ICountOptionCollection
Microsoft.AspNetCore.OData.Query.ICountOptionCollection.TotalCount.get -> long?Microsoft.AspNetCore.OData.Query.IODataQueryRequestParser
Microsoft.AspNetCore.OData.Query.IODataQueryRequestParser.CanParse(Microsoft.AspNetCore.Http.HttpRequest request) -> bool
Microsoft.AspNetCore.OData.Query.IODataQueryRequestParser.ParseAsync(Microsoft.AspNetCore.Http.HttpRequest request) -> System.Threading.Tasks.Task<string>
Microsoft.AspNetCore.OData.Query.ODataQueryContext
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.AspNetCore.OData/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext.ODataSerializerContext(Microsoft.AspNetCore.OData.Formatter.ResourceContext resource, Microsoft.OData.UriParser.SelectExpandClause selectExpandClause, Microsoft.OData.Edm.IEdmProperty edmProperty) -> void
Microsoft.AspNetCore.OData.Query.ICountOptionCollection.TotalCount.get -> long?
Microsoft.AspNetCore.OData.Query.IODataQueryRequestParser
Loading