Reputation: 1666
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 ?
Upvotes: 3
Views: 5947
Reputation: 1666
Adding Inheritance Support to OdataModelBuilder
Users can now define abstract entity types and entity types that derive from another entity type. OData doesn't support complex type inheritance.
This commit only adds support in the ModelBuilder. Support for inheritance in the ODataConventionModelBuilder, ODataMediaTypeFormatter and Query support is still pending.
Reference : http://aspnetwebstack.codeplex.com/SourceControl/changeset/f4c252a30e68
To solving above problem, use the following steps:
Upvotes: 2