4
votes

I've been trying to find the answer to this and haven't had any luck. Assume I have a model that looks something like this:

public class A
{
    public int Id {get;set}
    public ICollection<B> Bs {get;set;}
}

public class B
{
    public int Id {get;set}
    public ICollection<C> Cs {get;set;}
}

public class C
{
    public int Id {get;set}
    public string Something {get;set;}
}

Can I write a Web Api 2 OData controller while can be queried like so: /odata/A(1)/B(2)/C(3)/Something

If this is redundant please point me to the place I should look. Thanks!

2

2 Answers

3
votes

You can check http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-routing-conventions for the part of Custom Routing Conventions. Hope this will solve your problem.

0
votes

One way to add a conventional rule to support deep navigation as Qian described as above. In OData V4 you should be able to use attribute routing to support your URL. add a Route annotation to your controller like below:

[ODataRoute("/A({key})/B({key})/C({key})")]

please be noted the official webapi V4 support will come in June.