Not work with nested json array
I want use select command with nested json array but not work have a error.
The query specified in the URI is not valid. Can not resolve the segment identifier 'status.id' in query option.
Data
{
"status": [
{
"Id": 1,
"Caption": "empty",
"Color": "#7268A6"
},
{
"Id": 2,
"Caption": "open",
"Color": "#2FB45A"
},
{
"Id": 3,
"Caption": "close",
"Color": "#BC6A41"
},
{
"Id": 4,
"Caption": "broken",
"Color": "#FF6F69"
}
]
}
I want return
id, caption
HTTP Request
https://localhost:44359/api/Houses/StateHouses?$select=status.Id,status.Caption
Setup.cs
ConfigureServices
services.AddControllers(mvcOptions =>
mvcOptions.EnableEndpointRouting = false);
services.AddOData();
Configure
app.UseMvc(routeBuilder =>
{
routeBuilder.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
routeBuilder.MapODataServiceRoute("ODataRoute", "odata", GetEdmModel());
routeBuilder.EnableDependencyInjection();
});
//app.UseEndpoints(endpoints =>
//{
// endpoints.MapControllers();
//});
IEdmModel GetEdmModel()
{
var odataBuilder = new ODataConventionModelBuilder();
var status = odataBuilder.EntitySet<HouseState>("status");
status.EntityType.Count().Filter().OrderBy().Expand().Select();
return odataBuilder.GetEdmModel();
}
I use
ASP.NET API Core -v3.1.4
Microsoft.AspNetCore.OData -v7.4.1
@zanyar3 The syntax to select sub(nested) property is to use (SelectPath) or the nested $select.
- SelectPath: $select=status/Id
- nested select: $select=status($select=Id)
Here's a detail blog illustrating the usage of $select at https://devblogs.microsoft.com/odata/select-enhancement-in-asp-net-core-odata/
Hope it can help you.
@xuzhg Dear SelectPath & Nested select not work
https://localhost:44359/api/Houses/StateHouses?$select=status($select=Id)
or
https://localhost:44359/api/Houses/StateHouses?$select=status/Id
@zanyar3 Can you share me your repo?
Dear @xuzhg i was invited repo please accepted
@zanyar3 Sorry, i missed your last comment. However, would you please let me know the repo link? So far, i haven't received the invite. Can you let me know where can i check the invite? from Email? notification?
added as a collaborator on the repository. notify by email please accepted
@zanyar3 Was this issue resolved?
Closing this issue due to inactivity. If this issue still persists, feel free to create a new issue.