Open casually-creative opened 1 year ago
HI!
It looks like ODataQueryExpand
should be implemented with _hasMultyExpands
:
public IODataQueryExpand<TEntity> Expand(Expression<Func<TEntity, object>> expandNested)
{
var query = new ODataOptionExpandExpressionVisitor().ToQuery(expandNested);
Expand(query);
return this;
}
public IODataQueryExpand<TEntity> Expand(Action<IODataExpandResource<TEntity>> expandNested)
{
var builder = new ODataExpandResource<TEntity>(_odataQueryBuilderOptions);
expandNested(builder);
Expand(builder.Query);
return this;
}
...
private IODataQueryExpand<TEntity> Expand<T>(T query) where T : class
{
if (_hasMultyExpands)
{
_stringBuilder.Merge(ODataOptionNames.Expand, QuerySeparators.Nested, $"{QuerySeparators.Comma}{query}");
}
else
{
_stringBuilder.Append($"{ODataOptionNames.Expand}{QuerySeparators.EqualSign}{query}{QuerySeparators.Nested}");
}
_hasMultyExpands = true;
return this;
}
@ZEXSM I've created a fix - please let me know if you would like me to share it :)
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:
The result of this looks like:
while it should be this:
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.