私のプロジェクトは、ASP.Net MVC Web API 4 アプリケーションに基づいて作成されています。モデルの場合、次の実装があります。
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);
}
}
そのため、クライアント側アプリケーションで 1 つのリクエストが生成されると、次のようになります。
$.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 を使用して有効でないのはなぜですか?