Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deserializing top-level collections of entity types. #2707

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -54,7 +54,19 @@ public override object Read(ODataMessageReader messageReader, Type type, ODataDe
throw Error.Argument("edmType", SRResources.ArgumentMustBeOfType, EdmTypeKind.Complex + " or " + EdmTypeKind.Entity);
}

ODataReader resourceSetReader = readContext.IsChangedObjectCollection ? messageReader.CreateODataDeltaResourceSetReader() : messageReader.CreateODataResourceSetReader();
IEdmEntityType entityType = edmType.AsCollection().ElementType().Definition as IEdmEntityType;
IEdmEntitySet entitySet = null;
if(entityType != null)
{
// CreateODataDeltaResourceSetReader requires an entity set if you pass a type for reading a request.
// We can relax that check in ODataJsonlightInputContext, line 670.
// In the meantime, creating a dummy entity set allows the reader to know what type its reading so the payload
// doesn't have to be marked up with odata.type annotations.
IEdmEntityContainer container = new EdmEntityContainer(entityType.Namespace, "");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that we can create the reader using entity type only, right?

entitySet = new EdmEntitySet(container,"",entityType);
}

ODataReader resourceSetReader = readContext.IsChangedObjectCollection ? messageReader.CreateODataDeltaResourceSetReader() : messageReader.CreateODataResourceSetReader(entitySet, entityType);
object resourceSet = resourceSetReader.ReadResourceOrResourceSet();
return ReadInline(resourceSet, edmType, readContext);
}
Expand Down Expand Up @@ -135,16 +147,28 @@ public sealed override object ReadInline(object item, IEdmTypeReference edmType,
}
}

if (result != null && elementType.IsComplex())
if (result != null && (elementType.IsComplex() || elementType.IsEntity()))
{
if (readContext.IsUntyped)
{
EdmComplexObjectCollection complexCollection = new EdmComplexObjectCollection(edmType.AsCollection());
foreach (EdmComplexObject complexObject in result)
if (elementType.IsComplex())
{
EdmComplexObjectCollection complexCollection = new EdmComplexObjectCollection(edmType.AsCollection());
foreach (EdmComplexObject complexObject in result)
{
complexCollection.Add(complexObject);
}
return complexCollection;
}
else
{
complexCollection.Add(complexObject);
EdmEntityObjectCollection entityCollection = new EdmEntityObjectCollection(edmType.AsCollection());
foreach (EdmEntityObject entityObject in result)
{
entityCollection.Add(entityObject);
}
return entityCollection;
}
return complexCollection;
}
else
{
Expand Down