Imagine that we have a class named Contract, with a navigation property named Vendor, of type Vendor.
The Vendor class has a property named Name of type string.
I have an OData endpoint, that feeds the data grid with contract records. In the grid I also show the vendor's name in a column.
Now, when I sort based on the contract's primary fields, like number, start, end, all is good. But when I sort based on the vendor's name, the LoadDataArgs.OrderBy has a value of np(Vendor.name).
Now when the request is executed I see that the back end generated the error:
"The query specified in the URI is not valid. The child type 'Vendor.Name' in a cast was not an entity type. Casts can only be performed on entity types."
But if I change manually the request Uri in Postman to "vendor/Name" from "np(Vendor/Name)" is working fine. Am I missing something?
Thank you, George
P.S.: I tried filtering on the same column and the filter clause is (np(Vendor.Name)) = 'test' which generates the same error as before.
I am using AsOfDataEnumerable when I get the response back, as is in the example and yes I consulted the example when I was implementing my solution.
The example on the mentioned URL, is no using navigational properties, and as I wrote, if I apply filter or sorting on none navigation properties on my grid, then it works fine.
But when I apply filter or sorting on navigational properties, the value that is generated is matching what dynamic LINQ would expect. np(Vendor.Name) is for null propagation.
In your example if you had a navigational property, you would see that the function of getting customers would fail when executing the call "return await response.ReadAsync<ODataServiceResult>();". The call to the AsODataEnumerable, is executed after the request and response cycle. Am I wrong?
Thanks again for your response. Although your example is different than the one I was looking for, I was able to find the issue combining both of your comments.
The grid is bind to an IEnumerable collection and it had a default filter, which was applied before the call to the load data function, which returns the dataset as an ODataEnumerable. So the grid was assuming that it was creating LINQ filters and not OData. After applying the initial filter with your second example and not as a filter on the grid it worked fine. I hope you understand what I am trying to say.