1

Closed

ID defined in the base type

description

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:
<m:message>
Instance property 'PId' is not defined for type 'SimaticIT.S95Type.Domain.Interfaces.IOperation'
</m:message>
<m:type>System.ArgumentException</m:type>
<m:stacktrace>
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.

Thanks
Closed May 7 at 6: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.

comments

jacalvar wrote Apr 28 at 9:38 PM

Hi,

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);
                Console.ReadKey();
            }
        }

        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);
            mb.EntityType<IOperations>().DerivesFrom<IOperationsBase>().Abstract();
            mb.EntityType<Operations>().DerivesFrom<IOperations>();
            mb.EntitySet<IOperations>("Operations");
            config.Routes.MapODataServiceRoute("odata", "odata", mb.GetEdmModel());
            builder.UseWebApi(config);
        }
    }

    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
    {
        [EnableQuery]
        public IQueryable<Operations> Get()
        {
            return Enumerable.Range(1, 10).Select(i => new Operations { PId = i, AnotherProperty = i * 2 }).AsQueryable();
        }
    }

jacalvar wrote May 1 at 6:03 PM

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