6

Closed

Exception using [Queryable] attribute on classes inheriting a base class with List based properties

description

I've found that if you have a Get method decorated with the Queryable attribute it will fail with "navigation property not found" if the objects returned extend a base class with a List in it. I am just using plain objects. No Entity Framework. Ex:

public class Base
{
int Id {get; set;}
List<string> Links {get; set;}
}

public Company : Base
{
string Name { get; set;}
}

[Queryable]

public IQueryable<Company> Get()
{
...
}


The exception follow:

System.ArgumentException: The property does not belong to the specified type.
Parameter name: navigationProperty
at System.Web.Http.OData.Builder.EntityTypeConfiguration.AddNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity)
at System.Web.Http.OData.Builder.ODataConventionModelBuilder.MapEntityType(IEntityTypeConfiguration entity)
at System.Web.Http.OData.Builder.ODataConventionModelBuilder.MapTypes()
at System.Web.Http.OData.Builder.ODataConventionModelBuilder.GetEdmModel()
at System.Web.Http.HttpActionDescriptorExtensions.<>c__DisplayClass1.<GetEdmModel>b__0(Object _)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at System.Web.Http.HttpActionDescriptorExtensions.GetEdmModel(HttpActionDescriptor actionDescriptor, Type entityClrType)
at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)
at System.Web.Http.Filters.ActionFilterAttribute.<>c__DisplayClass2.<System.Web.Http.Filters.IActionFilter.ExecuteActionFilterAsync>b__0(HttpResponseMessage response)
at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass412.<Then>b__40(Task1 t)
Closed Oct 18, 2012 at 10:25 PM by hongyes
No longer repro in nightly build

comments

gardavis wrote Aug 22, 2012 at 2:34 PM

I got this same exception.

Before the MVC4 RTM, this worked. I created an entity model (.edmx) by dragging my Products table to the design surface and then writing a simple web api using [Queryable(ResultLimit-25)] on the Get() call returning IQueryable<Product>.

After RTM, [Queryable(ResultLimit-25)] was not recognized. I used NuGet to install the latest OData package today and though ResultLimit was not recognized, [Queryable] was.
    [Queryable]
    public IQueryable<Product> Get()
    {
        var context = new AentStoreEntities();
        return context.Products;
    }
Now when running http://mytestserver.com/api/products?$top=1

The exception occurs: The property does not belong to the specified type. Parameter name: navigationProperty.

As far as I know, there is no List<> in the model.

Thanks,
Gary Davis
Webguild

gardavis wrote Aug 22, 2012 at 2:36 PM

That should be ResultLimit=25, of course.

dcowan wrote Aug 24, 2012 at 2:08 AM

I just tried the nightly nuget build 0.1.0-alpha-120823 and I am still seeing the same issue

raghuramn wrote Aug 24, 2012 at 4:10 AM

@dcowan: 0.1.0-alpha-120823 is yesterday's build (technically today). The build runs at midnight. This package is generated at 8/23/2012 1:57 AM where as the commit for the fix went later. You should wait for 0.1.0-alpha-120824.

lukepuplett wrote Aug 30, 2012 at 7:19 PM

How frequently do you update the Nuget package source? This problem seems quite widespread (my model has no List) and would hit many people moving to MVC 4 RTM/VS2012 and who have used the excellent Queryable OData support.

dcowan wrote Aug 30, 2012 at 7:45 PM

I was able to get it the next day as described above and it fixed the issue I reported.

raghuramn wrote Aug 30, 2012 at 9:21 PM

@lukepuplett: we haven't published a new nuget package yet with these fixes. we are publishing nightly builds of this package on myget though. You can get them from http://www.myget.org/F/aspnetwebstacknightly/. More about that here http://aspnetwebstack.codeplex.com/discussions/353867

lukepuplett wrote Aug 31, 2012 at 1:36 PM

@raghuramn

Can't wait for the new package. No, actually I can't wait...

...for now I've written my own Expression Tree builder which covers filter, (top, skip and orderby coming soon) and its working and I learned some deeper Linqy stuff.

raghuramn wrote Sep 1, 2012 at 12:04 AM

@lukepuplett: Did you try the packages from http://www.myget.org/F/aspnetwebstacknightly/ ?