ID defined in the base type


The scenario is oData v4 (it worked in v3).
I am exposing the model as interfaces and it all works until I use the EnableQueryAttribute over the get method.
As soon as the attribute is applied, the following error comes out:
Instance property 'PId' is not defined for type 'SimaticIT.S95Type.Domain.Interfaces.IOperation'
at System.Linq.Expressions.Expression.Property(Expression expression, String propertyName)
 at System.Web.OData.Query.Expressions.FilterBinder.CreatePropertyAccessExpression(Expression source, IEdmProperty property)
 at System.Web.OData.Query.Expressions.FilterBinder.BindPropertyAccessQueryNode(SingleValuePropertyAccessNode propertyAccessNode)
 at System.Web.OData.Query.Expressions.FilterBinder.Bind(QueryNode node)
 at System.Web.OData.Query.Expressions.FilterBinder.BindExpression(SingleValueNode expression, RangeVariable rangeVariable, Type elementType)
 at System.Web.OData.Query.Expressions.FilterBinder.Bind(OrderByClause orderBy, Type elementType, IEdmModel model, ODataQuerySettings querySettings)
 at System.Web.OData.Query.OrderByQueryOption.ApplyToCore(IQueryable query, ODataQuerySettings querySettings)
 at System.Web.OData.Query.OrderByQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
 at System.Web.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
 at System.Web.OData.EnableQueryAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)
 at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)
 at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
 at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
The exposed entity IOperations derives from a base interface where the PId is defined.

I believe that PId should be searched in base types too.
I tried to add the base type to the EDM with no luck.

Closed May 7, 2014 at 7:57 AM by jacalvar
The model builder and the queries are not expected to work with hierarchies of interfaces.

In order to build a hierarchy on a model, classes should be used.


jacalvar wrote Apr 28, 2014 at 10:38 PM


I've tried reproing the issue and I couldn't. I'm not sure if it's because I'm building the Edm model in a different way. Here is my repro:
    class Program
        private static readonly string serverUrl = "http://localhost:12345/";
        static void Main(string[] args)
            using (WebApp.Start(serverUrl, Configuration))
                Console.WriteLine("Server listening on {0}", serverUrl);

        private static void Configuration(IAppBuilder builder)
            var config = new HttpConfiguration();
            var mb = new ODataModelBuilder();
            mb.EntityType<IOperationsBase>().Abstract().HasKey(p => p.PId).Property(p => p.AnotherProperty);
            config.Routes.MapODataServiceRoute("odata", "odata", mb.GetEdmModel());

    public interface IOperations : IOperationsBase


    public interface IOperationsBase
        int PId { get; set; }
        int AnotherProperty { get; set; }

    public class Operations : IOperations
        public int PId { get; set; }

        public int AnotherProperty { get; set; }

    public class OperationsController : ODataController
        public IQueryable<Operations> Get()
            return Enumerable.Range(1, 10).Select(i => new Operations { PId = i, AnotherProperty = i * 2 }).AsQueryable();

jacalvar wrote May 1, 2014 at 7:03 PM

Hi, to add more details to this bug. I tried this issue also in v3.0 and it didn't work either.