Codehelp
Codehelp

Reputation: 4747

How to have multiple entity sets for the same OData controller in ASP.NET MVC 5

I was following this sample to create Odata end-point

In this it says:

Note that an endpoint can have multiple entity sets. Call EntitySet for each entity set, and then define a corresponding controller.

Now, I cant have a controller for every single entity set and I want to give OData support.

If I want to have multiple entity sets in a single controller how do I go about doing it?

Regards.

Upvotes: 5

Views: 6314

Answers (2)

Tony
Tony

Reputation: 1307

This might be a decent sample to give you some ideas. It creates Dynamic OData Routes

https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/DynamicEdmModelCreation/

Upvotes: 1

Feng Zhao
Feng Zhao

Reputation: 2995

The default routing convention determines the controller name by the entity set name.

If you have multiple entity sets in a single controller, how can WebAPI select the correct controller?

Unless you use attribute routing convention or your self-defined routing convention for each action in the controller, which I think is ugly and not recommended.

Check this for attribute routing:

http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0.aspx

Upvotes: 0

Related Questions