My project is created based on ASP.Net MVC Web API 4 application. If it's model have the following implementations :
public class BaseEntity
{
public object Id {get; set;}
}
public class Entity1 : BaseEntity
{
public string Name {get; set;}
}
And Wep API controller is :
public class Entity1Controller : ApiController
{
...
[Queryable]
public IQueryable<T> Get()
{
return repository.Table.AsQueryable();
}
}
And Web API configuration have this setting :
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);
}
}
so, when one request is generated in the client side application :
$.getJSON("api/Entity1?$filter=Id eq '" + id + "'",
function (data) {
...
});
my application encounter with the following error :
{"Message":"The query specified in the URI is not valid.","ExceptionMessage":"Type 'Entity 1' does not have a property 'Id'."}
Why the query specified in the URI is not valid using Web API OData ?