In my case, I needed to set the maximum expansion depth in the entity when creating the edm model.
In the startup, you configure your route and your model:
routes.MapODataServiceRoute("odata", "odata", ODataDataSourceProvider.GetEdmModel(new ODataConventionModelBuilder()));
In your provider:
public IEdmModel GetEdmModel(ODataModelBuilder builder)
{
builder.EntitySet<Object>("Objects");
builder
.EntityType<Object>()
.Filter() // Enables filtering
.Expand(3) // Enables expanding with maximum depth: 3
.Select(); // Enables selecting
return builder.Build();
}
Then, in your controller you can override the maximum depth value, as long as it is less than the maximum defined in the entity configuration:
[HttpGet]
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All, MaxExpansionDepth = 2)]
public SingleResult<Object> Get(Guid key){ }