【发布时间】:2016-01-19 11:36:48
【问题描述】:
我有一个OData v4 Endpoint Using ASP.NET Web API,它有两个独立的模型
ModelVer1.Customer.cs
int ID;
string Name;
ModelVer2.Customer.cs
int ID;
string Name;
string Address;
webapiconfig.cs
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
ODataModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<ModelVer1.Customer>("Customers");
// If I use below get error:
// The entity set 'Customers' was already configured with a different EntityType ('Customer'). Parameter name: entityType
builder.EntitySet<ModelVer2.Customer>("Customers");
config.MapODataServiceRoute(
routeName: "ODataRoute",
routePrefix: "demo/api",
model: builder.GetEdmModel());
config.Services.Replace(typeof(IHttpControllerSelector), new CustomControllerSelector(config));
}
但出现错误:
实体集“客户”已经配置了不同的 实体类型(“客户”)。 参数名称:实体类型
应该怎么做?
我想我需要做类似
model: builder.GetEdmModel()这样的事情 需要动态生成这个模型来获取所有实体模型 ModelVersion1.Customer 和 ModelVersion2.Customer 等类
【问题讨论】:
标签: asp.net-web-api odata asp.net-web-api2