OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
853 stars 476 forks source link

Selecting properties in a nested complex type does not work #989

Closed ificator closed 4 years ago

ificator commented 7 years ago

Say I have a model where a Inner complex type is nested within an Outer complex (or entity) type, so a request without a $select would return:

{
  "outerProperty1": "foo",
  "outerProperty2": "bah",
  "inner": {
    "innerProperty1": "foo",
    "innerProperty2": "bah"
  }
}

According to the OData spec I should be able to write a query like ...?$select=outerProperty1,inner/innerProperty2 and have it return:

{
  "outerProperty1": "foo",
  "inner": {
    "innerProperty2": "bah"
  }
}

However what we actually get is an ODataException with message:

A path within the select or expand query option is not supported.

Assemblies affected

System.Web.OData

Reproduce steps

  1. Make a request against a resource with a complex type property, and include a $select statement that references just one of the properties within that complex type.

Expected result

The request succeeds, and only the requested property from the complex type is returned.

Actual result

The request fails.

Additional details

Issue #837 mentions this issue, but it seems prudent to track it specifically.

xuzhg commented 7 years ago

BingAds has this requirement.

daspek commented 7 years ago

Further, we need a compact syntax to represent this. Let's say we have this object:

{
  "outerProperty": "foo",
  "innerProperty": {
    "inner1": "foo",
    "inner2": "bah",
    "inner3": "baz",
    "inner4": "qux"
  }
}

We don't want to do $select=innerProperty/inner1,innerProperty/inner2,innerProperty/inner3. Instead, it should look like nested expand syntax: $select=innerProperty($select=inner1,inner2,inner3)

brjohnstmsft commented 7 years ago

@xuzhg Azure Search also has this requirement.

This seems to be a duplicate of https://github.com/OData/WebApi/issues/196 which as been open for a very long time. Any chance there will be traction on this soon?

FYI @robward-ms

brjohnstmsft commented 7 years ago

Also related: https://github.com/OData/odata.net/issues/513

ificator commented 7 years ago

It would also be nice if there was a capability of filtering collection properties that aren't navigations:

$select=collectionProperty($filter=name%20eq%20'foo')

brjohnstmsft commented 6 years ago

@xuzhg I propose closing this issue since it is a duplicate of #196. If you agree, please close this.