3
我的項目是基於ASP.Net MVC Web API 4應用程序創建的。如果它的模式有以下實現:在URI中指定的查詢無效使用Web API OData
public class BaseEntity
{
public object Id {get; set;}
}
public class Entity1 : BaseEntity
{
public string Name {get; set;}
}
和WEP API控制器:
public class Entity1Controller : ApiController
{
...
[Queryable]
public IQueryable<T> Get()
{
return repository.Table.AsQueryable();
}
}
和Web API配置此設置:
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
...
ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<BaseEntity>("BaseEntity");
modelBuilder.EntitySet<Entity1>("Entity1");
IEdmModel model = modelBuilder.GetEdmModel();
GlobalConfiguration.Configuration.SetEdmModel(model);
}
}
因此,當產生一個請求在客戶端應用程序中:
$.getJSON("api/Entity1?$filter=Id eq '" + id + "'",
function (data) {
...
});
,下面的錯誤我的應用程序的遭遇:
{"Message":"The query specified in the URI is not valid.","ExceptionMessage":"Type 'Entity 1' does not have a property 'Id'."}
爲什麼在URI指定的查詢使用Web API的OData是不是有效?
我發現了下面的鏈接,它確定在OData中支持ComplexType繼承:http://aspnetwebstack.codeplex.com/workitem/448 –