2

I have OData Webapi controllers with the following model: (all the code is also available in this github repo: https://github.com/Malyngo/ODataWebapiTest)

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int AddressId { get; set; }
    public Address Address { get; set; }
    public int WorkAddressId { get; set; }
    public Address WorkAddress { get; set; }
    public Customer Parent { get; set; }
    public IList<Customer> Children { get; set; }
}

public class Address
{
    public int Id { get; set; }
    public string Name { get; set; }

    public IList<Customer> Customers { get; set; }
}

Controller setup pretty standard, method for getting the customers looks like this:

public IHttpActionResult GetCustomers(ODataQueryOptions<Customer> queryOptions)
{
    try
    {
        queryOptions.Validate(_validationSettings);
    }
    catch (ODataException ex)
    {
        return BadRequest(ex.Message);
    }
    return Ok<IQueryable<Customer>>((IQueryable<Customer>)queryOptions.ApplyTo(customers));
}

When I do requests like: http://localhost:60272/odata/Customers?$orderby=Name it works without a problem.

But if I do something like this: http://localhost:60272/odata/Customers?$orderby=Address/Name,WorkAddress/Name

I get an error with the message:

The query specified in the URI is not valid. Duplicate property named 'Name' is not supported in '$orderby'

According to the github page for OData (https://github.com/OData/WebApi/issues/630) this is a bug that should have been fixed in v6.0.0, which I am using, but I still see this issue.

Am I doing something wrong? I have my code in a github repo here: https://github.com/Malyngo/ODataWebapiTest

Malyngo
  • 863
  • 7
  • 18

0 Answers0