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

added logic to allow query options in select=* calls #971

Draft
wants to merge 2 commits into
base: release-8.x
Choose a base branch
from
Draft
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 @@ -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")

Choose a reason for hiding this comment

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

Please delete unused code, you can always retrieve it from Git.

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

var wildcardSelectItem = selectItem as WildcardSelectItem;
if (wildcardSelectItem != null)

Choose a reason for hiding this comment

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

Please add tests for this senario

{
//// TODO this doesn't handle cases like $select=*,path/to/definedpropery
//// TODO the defined property gets added twice, but it shouldn't be; webapi could differentiate these cases by looking for '$', but really ODL should have "subsumed" items, and "non-subsumed" items to differentaite bewten the cases
foreach (var subsumedSelectItem in wildcardSelectItem.SubsumedSelectItems.Cast<PathSelectItem>().Where(item => item.HasOptions))

Choose a reason for hiding this comment

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

var subsumedSelectItems = wildcardSelectItem.SubsumedSelectItems.Cast().Where(item => item.HasOptions);

  foreach (var subsumedSelectItem in subsumedSelectItems)

{
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 +970,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