WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Not work with nested json array

Open zanyar3 opened this issue 5 years ago • 7 comments

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 avatar Jul 03 '20 21:07 zanyar3

@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 avatar Jul 06 '20 18:07 xuzhg

@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 avatar Jul 07 '20 21:07 zanyar3

@zanyar3 Can you share me your repo?

xuzhg avatar Jul 08 '20 00:07 xuzhg

Dear @xuzhg i was invited repo please accepted

zanyar3 avatar Jul 17 '20 21:07 zanyar3

@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?

xuzhg avatar Aug 10 '20 17:08 xuzhg

added as a collaborator on the repository. notify by email please accepted

zanyar3 avatar Aug 12 '20 06:08 zanyar3

@zanyar3 Was this issue resolved?

KenitoInc avatar Jul 04 '22 11:07 KenitoInc

Closing this issue due to inactivity. If this issue still persists, feel free to create a new issue.

KenitoInc avatar Feb 09 '23 16:02 KenitoInc