如何声明两个具有相同名称但在不同区域下路由的OData EntitySet?这可能吗?
例如:
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());
}
处理不同的请求,例如:
答案 0 :(得分:2)
在同一EDM模型中,不能有2个具有相同名称的不同实体。您必须创建两个不同的EDM模型和路线,如下所示 -
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());