Skip to content

Commit

Permalink
return count for selects with $count and * using ODataRoutingSample a…
Browse files Browse the repository at this point in the history
…nd requests to http://localhost:64771/v1/Customers?$select=FavoriteAddresses($count=true) and http://localhost:64771/v1/Customers?$select=FavoriteAddresses($count=true),*
  • Loading branch information
corranrogue9 committed Jun 23, 2023
1 parent 118c2c1 commit 8607b26
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,22 @@ private async Task WriteResourceAsync(object graph, ODataWriter writer, ODataSer
ResourceContext resourceContext = new ResourceContext(writeContext, structuredType, graph);

SelectExpandNode selectExpandNode = CreateSelectExpandNode(resourceContext);
/*if (expectedType.Definition.FullTypeName() == "ODataRoutingSample.Models.Customer")
{
var selectedProperty = selectExpandNode.SelectedComplexProperties.First(kvp => kvp.Key.Name == "FavoriteAddresses");
selectExpandNode.SelectedComplexProperties[selectedProperty.Key] = new PathSelectItem(
((writeContext.QueryOptions.SelectExpand.SelectExpandClause.SelectedItems.First() as WildcardSelectItem).SubsumedSelectItems.First() as PathSelectItem).SelectedPath,
null,
null,
null,
null,
null,
null,
true,
null,
null);
}*/

if (selectExpandNode != null)
{
ODataResource resource = CreateResource(selectExpandNode, resourceContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ internal Expression ProjectElement(QueryBinderContext context, Expression source

bool isSelectingOpenTypeSegments = isContainDynamicPropertySelection || IsSelectAllOnOpenType(selectExpandClause, structuredType);

//// propertiestoinclude is not null for the non-* case
if (propertiesToExpand != null || propertiesToInclude != null || computedProperties != null || autoSelectedProperties != null || isSelectingOpenTypeSegments)
{
//// TODO this returns null in our case
Expression propertyContainerCreation =
BuildPropertyContainer(context, source, structuredType, propertiesToExpand, propertiesToInclude, computedProperties, autoSelectedProperties, isSelectingOpenTypeSegments);

Expand Down Expand Up @@ -506,9 +508,11 @@ internal static IList<DynamicPathSegment> GetSelectExpandProperties(IEdmModel mo
}

// $select=...
//// TODO for * call, select item is a wildcard select item, which has nested pathselectitmes
PathSelectItem pathItem = selectItem as PathSelectItem;
if (pathItem != null)
{
//// TODO so we never enter the if body, and this next call is what adds the count to currentlevelpropertiestoincldue for the non-* case
DynamicPathSegment dynamicSegment = ProcessSelectedItem(pathItem, navigationSource, currentLevelPropertiesInclude);

This comment has been minimized.

Copy link
@corranrogue9

corranrogue9 Jun 27, 2023

Author Contributor

$select=* should also include dynamic properties, check if this is being handled correctly today

if (dynamicSegment != null)
{
Expand All @@ -517,6 +521,19 @@ internal static IList<DynamicPathSegment> GetSelectExpandProperties(IEdmModel mo
continue;
}

var wildcardSelectItem = selectItem as WildcardSelectItem;
if (wildcardSelectItem != null)
{
foreach (var subsumedSelectItem in wildcardSelectItem.SubsumedSelectItems.Cast<PathSelectItem>())
{
DynamicPathSegment dynamicSegment = ProcessSelectedItem(subsumedSelectItem, navigationSource, currentLevelPropertiesInclude);
if (dynamicSegment != null)
{
dynamicsSegments.Add(dynamicSegment);
}
}
}

// Skip processing the "WildcardSelectItem and NamespaceQualifiedWildcardSelectItem"
// ODL now doesn't support "$select=property/*" and "$select=property/NS.*"
}
Expand Down Expand Up @@ -951,6 +968,7 @@ internal void BuildSelectedProperty(QueryBinderContext context, Expression sourc

Expression nullCheck = GetNullCheckExpression(structuralProperty, propertyValue, subSelectExpandClause);

//// TODO if countoption is null, this returns a bogus expression
Expression countExpression = CreateTotalCountExpression(context, propertyValue, pathSelectItem.CountOption);

// be noted: the property structured type could be null, because the property maybe not a complex property.
Expand Down

0 comments on commit 8607b26

Please sign in to comment.