diff --git a/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSerializer.cs b/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSerializer.cs index c4c6bc9ee..7d0382a5b 100644 --- a/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSerializer.cs +++ b/src/Microsoft.AspNetCore.OData/Formatter/Serialization/ODataResourceSerializer.cs @@ -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); diff --git a/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs b/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs index 5057ba816..ab48dc259 100644 --- a/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs +++ b/src/Microsoft.AspNetCore.OData/Query/Expressions/SelectExpandBinder.cs @@ -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); @@ -506,9 +508,11 @@ internal static IList 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) { @@ -517,6 +521,21 @@ internal static IList GetSelectExpandProperties(IEdmModel mo continue; } + var wildcardSelectItem = selectItem as WildcardSelectItem; + if (wildcardSelectItem != null) + { + //// 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().Where(item => item.HasOptions)) + { + 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.*" } @@ -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.