Search code examples
odataodata-v4

OData also apply $expand in children on self-referencing entity


I have a self-referencing entity, and I need to $expand=Other on each level.

Expected result:

{
    Id: 1,
    Other: {...},
    Children: [
        {
            Id: 2,
            Other: {...},
            Children: [...]
        }
    ],
    ...
}

But I can't figure out how to write the query.

/odata/Entities/$expand=Children($levels=max),Other yields

{
    Id: 1,
    Other: {...},
    Children: [
        {
            Id: 2,
            Children: [...]
        }
    ],
    ...
}

The child (Id: 2) is missing Other.


Solution

  • Here you go

    /odata/Entities/$expand=Children($levels=max;$expand=Other),Other