guylegend
guylegend

Reputation: 85

Can you declare 2 OData resource EntitySets with the same name?

How do I declare two OData EntitySets with the same name but routed under different areas? Is this possible?

For example:

public static void Register(HttpConfiguration config)
{
   var builder = new ODataConventionModelBuilder();
   builder.EntitySet<Costco.Models.Food>("Foods");
   builder.EntitySet<Ikea.Models.Food>("Foods"); // this causes an exception
   config.Routes.MapODataServiceRoute("MyRoute", "{area}", builder.GetEdmModel());
}

to handle different requests like:

GET http://localhost/MyApp/Costco/Foods

GET http://localhost/MyApp/Ikea/Foods

Upvotes: 2

Views: 689

Answers (1)

Vinit
Vinit

Reputation: 2607

You cannot have 2 differnet entities with same name in same EDM model. You have to create two different EDM models and routes like below -

var costcoBuilder = new ODataConventionModelBuilder();
costcoBuilder.EntitySet<Costco.Models.Food>("Foods");

var ikeaBuilder = new ODataConventionModelBuilder();
ikeaBuilder.EntitySet<Ikea.Models.Food>("Foods");

config.Routes.MapODataServiceRoute("CostcoRoute", "Costco", costcoBuilder.GetEdmModel());
config.Routes.MapODataServiceRoute("IkeaRoute", "Ikea", ikeaBuilder.GetEdmModel());

Upvotes: 2

Related Questions