1

Closed

Queryable can't query on nested type property

description

To repro, using the model:
public class NestedClass_Parent
{
    public class Nest
    {
        public string Name { get; set; }
        public NestPropertyType NestProperty { get; set; }
    }

    public class NestPropertyType
    {
        public string Name { get; set; }
    }
}

public class NestedClassController : ApiController
{
    [HttpGet]
    public IQueryable<WebStack.QA.Test.OData.QueryComposition.NestedClass_Parent.Nest> QueryOnNestClass()
    {
        return new WebStack.QA.Test.OData.QueryComposition.NestedClass_Parent.Nest[]
        {
            new WebStack.QA.Test.OData.QueryComposition.NestedClass_Parent.Nest()
            {
                Name = "aaa",
                NestProperty = new NestedClass_Parent.NestPropertyType()
                {
                    Name = "aaa"
                }
            },
            new WebStack.QA.Test.OData.QueryComposition.NestedClass_Parent.Nest()
            {
                Name = "bbb",
                NestProperty = new NestedClass_Parent.NestPropertyType()
                {
                    Name = "bbb"
                }
            }
        }.AsQueryable();
    }
}
Sending request to server:
    [Fact]
    public void QueryOnPropertyWithNestedTypeShouldWork()
    {
        var response = this.Client.GetAsync(this.BaseAddress + "/api/NestedClass/QueryOnNestClass?$filter=NestProperty/Name eq 'aaa'").Result;
        response.EnsureSuccessStatusCode();

        var actual = response.Content.ReadAsAsync<WebStack.QA.Test.OData.QueryComposition.NestedClass_Parent.Nest[]>().Result;

        Assert.Equal("aaa", actual.Single().NestProperty.Name);
    }
The error returned from server is:
Response StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Wed, 17 Oct 2012 22:54:37 GMT
Server: Microsoft-HTTPAPI/2.0
Content-Length: 1931
Content-Type: application/json; charset=utf-8
}
Respose Content: {"Message":"The query specified in the URI is not valid.","ExceptionMessage":"Type 'WebStack.QA.Test.OData.QueryComposition.Nest' does not have a property 'NestProperty'.","ExceptionType":"Microsoft.Data.OData.ODataException","StackTrace":" at Microsoft.Data.OData.Query.MetadataBinder.BindNavigationProperty(NavigationPropertyToken segmentToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.Data.OData.Query.MetadataBinder.BindPropertyAccess(PropertyAccessQueryToken propertyAccessToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.Data.OData.Query.MetadataBinder.BindBinaryOperator(BinaryOperatorQueryToken binaryOperatorToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.Data.OData.Query.MetadataBinder.ProcessFilter(QueryNode query, QueryToken filter)\r\n at Microsoft.Data.OData.Query.MetadataBinder.BindTree(SyntacticTree syntax)\r\n at Microsoft.Data.OData.Query.MetadataBinder.BindQuery(SyntacticTree syntax)\r\n at Microsoft.Data.OData.Query.SemanticTree.ParseUri(Uri queryUri, Uri serviceBaseUri, IEdmModel model, Int32 maxDepth)\r\n at Microsoft.Data.OData.Query.SemanticTree.ParseUri(Uri queryUri, Uri serviceBaseUri, IEdmModel model)\r\n at System.Web.Http.OData.Query.FilterQueryOption.get_QueryNode()\r\n at System.Web.Http.OData.Query.FilterQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings, IAssembliesResolver assembliesResolver)\r\n at System.Web.Http.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n at System.Web.Http.QueryableAttribute.ExecuteQuery(IEnumerable query, HttpRequestMessage request, HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"}
Test 'WebStack.QA.Test.OData.QueryComposition.NestedClassTests.QueryOnPropertyWithNestedTypeShouldWork [Self-Host Trace:<NULL>]' failed:
System.Net.Http.HttpRequestException : Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
QueryComposition\NestedClassTests.cs(87,0): at WebStack.QA.Test.OData.QueryComposition.NestedClassTests.QueryOnPropertyWithNestedTypeShouldWork()
Closed Jan 3 at 12:53 AM by hongyes
Verified

comments

youssefm wrote Oct 18, 2012 at 7:24 PM

Underlying issue here is that the conventional model builder doesn't recognize the nested type property, and generates an incomplete model.

HongmeiG wrote Oct 18, 2012 at 9:22 PM

Moving this out to RTM as the scenario is not that common.