OData, Web Api 2 and Deeply Nested Objects

I tried to find the answer to this question and no luck. Suppose 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 when it can be requested as follows: / OData / A (1) / B (2) / C (3) / Something

If this is redundant, tell me the place I should look at. Thank!

+4
source share
2 answers

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

+2

Qian, . OData V4 URL-. , :

[ODataRoute ( "/ ({})/ ({})/ ({})" )]

, , webapi V4 .

0

Source: https://habr.com/ru/post/1528023/


All Articles