Skip to content

Commit

Permalink
Issue OData#360 Add basic support in Restier
Browse files Browse the repository at this point in the history
  • Loading branch information
VikingsFan committed May 12, 2016
1 parent 8181c40 commit 7636b6a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Web.OData.Formatter.Serialization;
using System.Web.OData.Query.Expressions;
using Microsoft.OData.Core;
using Microsoft.OData.Edm;
using Microsoft.Restier.WebApi.Results;

namespace Microsoft.Restier.WebApi.Formatter.Serialization
Expand Down Expand Up @@ -40,9 +43,35 @@ public override void WriteObject(
{
graph = collectionResult.Query;
type = collectionResult.Type;
if (WriteAggregationResult(graph, type, messageWriter, writeContext, collectionResult.EdmType))
{
return;
}
}

base.WriteObject(graph, type, messageWriter, writeContext);
}

private bool WriteAggregationResult(
object graph,
Type type,
ODataMessageWriter messageWriter,
ODataSerializerContext writeContext,
IEdmTypeReference feedType)
{
if (typeof(IEnumerable<DynamicTypeWrapper>).IsAssignableFrom(type))
{
var entitySet = writeContext.NavigationSource as IEdmEntitySetBase;
IEdmTypeReference elementType = feedType.AsCollection().ElementType();
if (elementType.IsEntity())
{
IEdmEntityTypeReference entityType = elementType.AsEntity();
ODataWriter writer = messageWriter.CreateODataFeedWriter(entitySet, entityType.EntityDefinition());
base.WriteObjectInline(graph, feedType, writer, writeContext);
return true;
}
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1001,5 +1001,14 @@ public void TestCountQueryOptionIsFalse(string uriStringAfterServiceRoot)
{
this.TestGetPayloadDoesNotContain(uriStringAfterServiceRoot, "@odata.count");
}

[Theory]
[InlineData("People?$apply=aggregate(Concurrency with sum as Result)", "Result")]
[InlineData("People?$apply=aggregate(PersonId with sum as Total)/filter(Total eq 78)", "Total")]
[InlineData("People?$apply=groupby((FirstName), aggregate(PersonId with sum as Total))", "Total")]
public void TestApplyQueryOption(string uriStringAfterServiceRoot, string expectedSubString)
{
this.TestGetPayloadContains(uriStringAfterServiceRoot, expectedSubString);
}
}
}

0 comments on commit 7636b6a

Please sign in to comment.