-
Notifications
You must be signed in to change notification settings - Fork 160
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
Default Expanding of Navigation Properties in OData v9 for Complex Types #1328
Comments
I'm a bit confused by your "current" vs "expected". You want just some properties of Can you add a full example with all properties you are getting vs what you want? Keep in mind "expand" is only about navigations. If you want other properties to not show that are not navigations you are now talking about "select", which is different. |
You can ignore my commented line [
{
"PersonDetails": {
"PersonNumber": "5255",
"FirstName": "Jack"
},
"PinCode": 52002
},
{
"PersonDetails": {
"PersonNumber": "5435",
"FirstName": "Phill"
},
"PinCode": 54213
}
] Expected Output: [
{
"PersonDetails": {
"Orders": [
{
"OrderNumber": "E528155",
"Cost": 2345,
}
],
"PersonNumber": "5255",
"FirstName": "Jack"
},
"PinCode": 52002
},
{
"PersonDetails": {
"Orders": [
{
"OrderNumber": "E528155",
"Cost": 213
}
],
"PersonNumber": "5435",
"FirstName": "Phill",
},
"PinCode": 54213
}
] I want my orders entity in my personDetails to be expanded by default |
@KavyaNelli
|
Adding this line is not expanding my orders(suspecting that my Address is a complex type) And we also have many nested entites hence we donot want to go with this approach, because doing it at every level will be difficult. Adding [AutoExpand] for Orders will expand all the properties, we have other endpoints where we dont want to expand all the properties. |
@KavyaNelli With the below setup, I can return the expected result. Controllerpublic class PersonDetailsController : ODataController
{
public PersonDetailsController() { }
private static IEnumerable<Address> _addresses = new List<Address>
{
new Address { PinCode = 123456, PersonDetails = new PersonDetails { PersonNumber = "123", FirstName = "John", Orders = new List<Order> { new Order { Id = 1, Amount = 100 } } } },
new Address { PinCode = 456789, PersonDetails = new PersonDetails { PersonNumber = "456", FirstName = "Jane", Orders = new List<Order> { new Order { Id = 2, Amount = 200 }, new Order { Id = 3, Amount = 1000 } } } }
};
[HttpGet("odata/PersonDetails/AddressLevel")]
public IActionResult AddressLevel()
{
return Ok(_addresses);
}
} EdmModelpublic static IEdmModel GetEdmModel()
{
var builder = new ODataConventionModelBuilder();
builder.Namespace = "NS";
builder.EntitySet<PersonDetails>("PersonDetails");
var personDetailsType = builder.EntityType<PersonDetails>();
personDetailsType
.Function("AddressLevel")
.ReturnsCollection<PersonDetails>();
return builder.GetEdmModel();
} Response: /PersonDetails/AddressLevel[
{
"pinCode": 123456,
"personDetails": {
"personNumber": "123",
"firstName": "John",
"orders": [
{
"id": 1,
"amount": 100
}
]
}
},
{
"pinCode": 456789,
"personDetails": {
"personNumber": "456",
"firstName": "Jane",
"orders": [
{
"id": 2,
"amount": 200
},
{
"id": 3,
"amount": 1000
}
]
}
}
] |
@WanjohiSammy that's not an OData payload. Does it make a difference if you change the code like this: -public IActionResult AddressLevel()
+public ActionResult<IEnumerable<Address>> AddressLevel()
{
- return Ok(_addresses);
+ return _addresses;
} |
Assemblies affected
v9
Describe the bug
I’m working with OData v9 and am currently facing an issue when trying to return a complex type from an OData function that includes a navigation property.
Scenario: I have defined a complex type Address in my EDM, which includes a navigation property PersonDetails that links to the PersonDetails entity. The PersonDetails entity further includes a collection navigation property to Orders.
Reproduce steps
The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue.
Data Model
Model Definition:
builder.ComplexType<Address>();
EDM Metadata:
I have referred to below links for insights into this limitation, but I'm open to any other suggestions or workarounds that might help achieve the expected output.
[https://github.com/OData/WebApi/issues/2669]
[https://github.com//issues/1275]
The text was updated successfully, but these errors were encountered: