Finally OData 7.x supports and ASP.NET Core 2.x

Finally we can create OData (v4) services using ASP.NET Core.

My first impression, it’s ok, plus it has extra features.

Use my startup project, on Github as a sample. (It’s tricky to forget to enable features like Filter, otherwise you’ll and up with :

value":"The query specified in the URI is not valid. The property 'Id' cannot be used in the $filter query option."}

So, this is the Configure section

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
       {
           if (env.IsDevelopment())
           {
               app.UseDeveloperExceptionPage();
           }
           var builder = new ODataConventionModelBuilder(app.ApplicationServices);
           builder.EntitySet("Cars");
      
           app.UseMvc(routeBuilder =>
           {
               routeBuilder.Count().Filter().OrderBy().Select().MaxTop(null).Expand();
               routeBuilder.MapODataServiceRoute("ODataRoute", "odata", builder.GetEdmModel());
               // Work-around for #1175

               routeBuilder.EnableDependencyInjection();
           } ) ;
       }

To get PATCH and POST working, we need the [FromBody] Attribute like here

public async Task Post([FromBody] Car newCar)

 

The sample, is downloadable here (ASP.NET-Core-With-Odata-7)

blog comments powered by Disqus