Customize OData Options
You can customize OData options in the Startup.cs file. Use the services.AddControllers().AddOData method for this purpose.
Change the Expansion Depth for Related Business Objects
To specify the ODataValidationSettings.MaxExpansionDepth option, follow the steps below:
Implement a custom ODataQueryValidator service to set MaxExpansionDepth:
using Microsoft.AspNetCore.OData.Query.Validator; using Microsoft.AspNetCore.OData.Query; // ... public class MyODataQueryValidator : ODataQueryValidator { public override void Validate(ODataQueryOptions options, ODataValidationSettings validationSettings){ validationSettings.MaxExpansionDepth = 3; base.Validate(options, validationSettings); } }
Replace the default ODataQueryValidator service with the custom service in the ConfigureServices method:
File: MySolution.WebApi\Startup.cs (MySolution.Blazor.Server\Startup.cs)
public void ConfigureServices(IServiceCollection services) { // ... services.AddControllers().AddOData(options => { options .EnableQueryFeatures(100) .AddRouteComponents("api/odata", new XafApplicationEdmModelBuilder(services).GetEdmModel(), odataServices => { odataServices.AddSingleton<ODataQueryValidator, MyODataQueryValidator>(); }); }); // ... }