3
votes

Is there a way to auto expand nested entity in the response with odata 5.7?

Because by default we have to add ?$expand=myNestedEntity

2
Hi @Jag. If my answer below has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself.lencharest

2 Answers

7
votes

In your entity class definition, use the AutoExpand attribute on the navigation properties you would like to have expanded.

Namespace: Microsoft.AspNet.OData.Builder

Represents an Attribute that can be placed on a navigation property to specify it is auto expanded, or placed on a class to specify all navigation properties are auto expanded.

5
votes

As an alternative, this can be accomplished with fluent api.

builder.EntitySet<MyType>("MyType").EntityType.Expand(SelectExpandType.Automatic, "ExpandedField1", "ExpandedField2");