I'm having some issues trying to configure batching for OData on an AspNETCore Web Application. I've searched everywhere (almost) and couldn't find a proper answer. I'm not sure that the current AspNetCore.Odata version 7.0.0 which is still beta has support for batching.
As far as I am concerned, configuring batching seems impossible now since the MapODataServiceRoute
method (from the AspNetCore assemply) doesn't seem to receive any ODataBatchHandler
as in .NET common Odata.
app.UseMvc(routes =>
{
routes.Count().Filter().OrderBy().Expand().MaxTop(null);
routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel()); //Doesn't receive any ODataBatchHandler
routes.EnableDependencyInjection();
});
If someone came across this batching issue for Odata core, some advice would be pretty helpful. Thanks!
Please refer to OData Protocol for more detail about batch, and Batch in ODL for batch in ODL client. It is very easy to enable batch in an OData service which is built by Web API OData. As above, we only need to create a new batch handler and pass it when mapping routing for OData service. Batch will be enabled.
In this document, we will walk through the process of creating a local service using OData 8.0, which is optimized to support ASP.NET Core 5. To learn more about the changes, check out ASP.NET Core OData 8.0 Preview for .NET 5 (which also references ASP.NET Core OData now Available ), written by my colleague, Sam.
In ASP.NET Core OData, it’s easy to build the EDM based on the above CLR types ( Entity, Complex, Enum ). With that in mind, let’s add the following private static method at the end of Startup.cs, which actually builds a model from the classes we’ve just defined. Now, we have defined two entity sets named “ Books ” and “ Presses ”.
Applies To :# OData WebApi v7 for aspnet webapi supported OData AspNet WebApi V7# OData Webapi for Webapi supported OData AspNet WebApi V6 Batch requests allow grouping multiple operations into a single HTTP request payload and the service will return a single HTTP response with the response to all operations in the requests.
Try replace the existing ConfigureServices
and Configure
methods with the following code:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddOData();
}
public void Configure(IApplicationBuilder app)
{
var builder = new ODataConventionModelBuilder(app.ApplicationServices);
builder.EntitySet<Product>("Products");
app.UseMvc(routeBuilder =>
{
routeBuilder.Select().Expand().Filter().OrderBy().MaxTop(100).Count();
routeBuilder.MapODataServiceRoute("ODataRoute", "odata", builder.GetEdmModel());
routeBuilder.EnableDependencyInjection();
});
}
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