0
votes

I'm using OData in WebAPI (with Entity Framework models) and it seems to be working a treat. However I have an entity/controller called NominalAccounts, where the controller is called 'NominalAccountsController', the DB entity is 'NominalAccount' and the OData path I want to use is 'nominal_accounts' (i.e. http://test/api/nominal_accounts ). So I have the below code in the Startup class:

 builder.EntitySet<NominalAccount>("nominal_accounts");

But this seems to fail because the it looks for the controller with an underscore. Is there a way to define, for an entity set, which controller it should look for?

1

1 Answers

0
votes

I don't know what your setup looks like, but I have one controller for each entity. And for my controllers to have a specific endpoint I simply use a ODataRoutePrefix-prefix:

using System.Web.Http;
using System.Web.OData;
using System.Web.OData.Query;
using System.Web.OData.Routing;

[ODataRoutePrefix("nominal_accounts")]
public class NominalAccountsController : ODataController
{
    [EnableQuery]
    public virtual IQueryable<NominalAccount> Get(ODataQueryOptions<NominalAccount> q)
    {
        return _your_odata_source;
    }
}

And my config like so:

IEdmModel model = GenerateModel();
config.MapODataServiceRoute(routeName: "ODataRoute", routePrefix: "odata", model: model);