Skip to content

Commit

Permalink
fix $apply with $groupby with more than one property
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethOkerio committed Aug 9, 2023
1 parent ddc59f7 commit 9cb3fdf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ public static IQueryable ApplyBind(this IOrderByBinder binder, IQueryable query,
throw Error.ArgumentNull(nameof(context));
}

context.EnsureFlattenedProperties(context.CurrentParameter, query);

OrderByBinderResult orderByResult = binder.BindOrderBy(orderByClause, context);
IQueryable querySoFar = query;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ private IOrderedQueryable ApplyToCore(IQueryable query, ODataQuerySettings query
binderContext.AddComputedProperties(Compute.ComputeClause.ComputedItems);
}

binderContext.EnsureFlattenedProperties(binderContext.CurrentParameter, query);

foreach (OrderByNode node in nodes)
{
OrderByPropertyNode propertyNode = node as OrderByPropertyNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ public async Task GroupByWithAggregationAndOrderByDynamicPropsWorks()
Assert.Equal(expectedResult, stringObject.ToString());
}

[Fact]
public async Task GroupByMoreThanOnePropertyWithDollarTopWorks()
{
// Arrange
string queryUrl = "aggregation/Orders?$apply=groupby((Id, Name),aggregate(Price with sum as TotalPrice))&$top=1";
string expectedResult = "{\"value\":[{\"Name\":\"Order2\",\"Id\":1,\"TotalPrice\":25}]}";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, queryUrl);
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata.metadata=none"));

// Act
HttpResponseMessage response = await Client.SendAsync(request);

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var stringObject = await response.Content.ReadAsStringAsync();

Assert.Equal(expectedResult, stringObject.ToString());
}

[Fact]
public async Task AggregationWithFilterWorks()
{
Expand Down

0 comments on commit 9cb3fdf

Please sign in to comment.