Skip to content

OData Batching

Chris Martinez edited this page Nov 3, 2020 · 4 revisions

OData batch operations are meant to execute the same way that other requests do; however, there may be some minor, but crucial differences required in the setup configuration depending on your target platform.

ASP.NET Core and OData v4.0

OData batch operations are facilitated by the OData batching middleware in ASP.NET Core. API Versioning also has its own middleware that is automatically registered for you. When combining API Versioning and OData batching, the order of middleware registration becomes important. In order for OData batching to work properly, automatic middleware registration for API Versioning must be disabled and imperatively registered at the appropriate time.

Step 1

Disable automatic registration of the API Versioning middleware.

services.AddApiVersioning( options => options.RegisterMiddleware = false );

Step 2

Register the API Versioning middleware after the OData batching middleware.

public void Configure( IApplicationBuilder app, VersionedODataModelBuilder modelBuilder )
{
  app.UseODataBatching();
  app.UseApiVersioning();
  app.UseRouting();
  app.UseEndpoints(
    endpoints =>
    {
        var models = modelBuilder.GetEdmModels( "api" );
        var batchHandler = new DefaultODataBatchHandler();

        endpoints.MapControllers();
        endpoints.MapVersionedODataRoute( "odata", "api", models, batchHandler );
    } );
}
Clone this wiki locally