简体   繁体   English

如何使用OData v4 6.0.0在.NET中进行嵌套的OData调用?

[英]How can I make a nested OData call in .NET using OData v4 6.0.0?

Assuming I have the following in my WebApiConfig.cs: 假设我在WebApiConfig.cs中有以下内容:

        modelBuilder.EntitySet<Content>("Content");
        modelBuilder.EntitySet<Area>("Area");

And I have the following classes: 我有以下课程:

public class Area
{
    public string Id { get; set; }

    public ICollection<Content> Contents { get; set; }
}

public class Content
{
    public string Id { get; set; }

    [ForeignKey("Area")]
    public int? AreaId { get; set; }
    public virtual Area Area { get; set; }
}

How can I make an ODataController action method that is bound to the following route? 如何创建绑定到以下路由的ODataController操作方法?

GET /odata/Area(Id)/Content(Id)

When I try to make a custom routing convention, I keep getting the following ODataPath: 当我尝试制作自定义路由约定时,我不断获得以下ODataPath:

"~/entityset/key/unresolved"

and I'm trying to get this: 我想要得到这个:

"~/entityset/key/navigation/key"

Note: I am using v6.0.0 of the v4 OData, so some of the routing has changed from previous versions. 注意:我使用的是v4 OData的v6.0.0,因此某些路由已从先前版本更改。

The name Content in the URL /odata/Area(Id)/Content(Id) needs to match the name of the navigation property on the class Area . 名称Content的URL /odata/Area(Id)/Content(Id)需要相匹配,对类导航属性的名称Area On your class in the question, it is called Contents 在你的课堂上,它被称为Contents

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM