Hi Everyone,
I need a setting in Get() method [EnableQuery(MaxExpansionDepth=3)] to limit expansion depth in OData query.
I tried to set this attribute in Get() method but it does not work.
Could you please give me a suggestion for this?
Follow as : https://github.com/OData/odata.net
Many Thanks
[EnableQuery(MaxExpansionDepth = 4)]
public IQueryable<abc> Get()
{
return GetAQueryable<abc>();
}
before your method name add it.
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){ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With