Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspNETCore Odata Batching

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!

like image 271
Iustinian Andrioaie Avatar asked Feb 22 '18 14:02

Iustinian Andrioaie


People also ask

How to enable batch In OData service?

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.

Which OData version is optimized for ASP NET Core 5?

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.

How to build an EDM using OData in ASP NET Core?

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 ”.

Which OData WebAPI version does ASPnet WebAPI support?

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.


1 Answers

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();
    });
}
like image 125
Kousic Avatar answered Oct 05 '22 01:10

Kousic