4

I have been trying to use OData with Dot Net Core, but wasn't successful in doing so. I feel this hasn't been port to the same (I may be wrong here). In this case, is there any alternatives to OData in .Net Core?

Any suggestions are welcome.

Santyy
  • 166
  • 1
  • 12
  • 1
    Refer this - http://stackoverflow.com/questions/39279552/odata-support-in-asp-net-core – Sanket Sep 30 '16 at 04:54
  • 1
    Possible duplicate of [OData Support in ASP.net core](https://stackoverflow.com/questions/39279552/odata-support-in-asp-net-core) – Chui Tey Oct 02 '17 at 00:24

1 Answers1

2

You can install the latest AspNetCore.Odata nugget package and start from there:

https://www.nuget.org/packages/Microsoft.AspNetCore.OData/

In your Startup.cs class make sure that you configure your services to use OData:

 public void ConfigureServices(IServiceCollection services)
    {

        services.AddOData();
        services.AddMvc();
    }

Also, in the Configure method make sure to map the Odata Service Route:

 app.UseMvc(routes =>
        {
            routes.Count().Filter().OrderBy().Expand().MaxTop(null);
            routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());
            routes.EnableDependencyInjection();
        });
  • Thanks for providing correct configurations. How can i access the service? My controller route is api/students when i hit this url am not getting anything as response. – user3625533 Jul 14 '18 at 18:32
  • I don't really understand your question. You don't have to access any service beside configuring the above in the Startup.cs file. You'll have to create your own Controller and create a method for api/students which returns some data. – Iustinian Andrioaie Jul 20 '18 at 11:42
  • thanks for the response. I figured out the issue with my dapper extension which is causing the error and not returning any rows from DB hence am getting a empty response. The above configurations worked for me. – user3625533 Jul 20 '18 at 13:46
  • Now i have another problem handling versions with OData. I have 2 versions of API's and i want to implement OData for version2 but, when i provided the same configuration am getting route conflict with version1 API. How can i tell the OData to use for only version2 API and version1 should run as it is. – user3625533 Jul 23 '18 at 13:13
  • I don't think you can use 2 different configurations for the routes. My best advice would be to create a new project for you v2 functionality and add a v2 to the route. For example, ../odata/v2/Entities. – Iustinian Andrioaie Jul 24 '18 at 09:59