Skip to content

Multiple expands, nested in another expand, produce a wrong query string. #110

@casually-creative

Description

@casually-creative

When nesting multiple expands inside another expand, the resulting odata query string contains multiple $expand tags in that nest, whilst they should be grouped into one $expand with comma seperated entity references.

Here is an invented code sample:

string oDataQuery = new ODataQueryBuilder()
    .For<RootEntity>("root_entity")
    .ByList()
    .Expand(er => er
        .For<MainRelatedEntity>(root => root.SomeListProperty)
        .Expand(em => em
            .For<SubRelatedEntity1>(main => main.SubProperty1)
            .Select(sub1 => sub1.some_property)
        )
        .Expand(em => em
            .For<SubRelatedEntity2>(main => main.SubProperty2)
            .Select(sub2 => sub2.some_property)
        )
    )
    .ToUri()
    .ToString();

The result of this looks like:

root_entity?$expand=SomeListProperty($expand=SubRelatedEntity1($select=some_property);$expand=SubRelatedEntity2($select=some_property))

while it should be this:

root_entity?$expand=SomeListProperty($expand=SubRelatedEntity1($select=some_property),SubRelatedEntity2($select=some_property))

When sending the first request to my oData endpoint, it obviously ignores the first sub expand, and only takes into account the last one.


When expanding multiple relations on the root level, so without the nesting inside the MainRelatedEntity, then it works as expected. The key here is that they are nested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions