Reputation: 85
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:
Upvotes: 2
Views: 689
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