【问题标题】:How to get OData navigation properties如何获取 OData 导航属性
【发布时间】:2014-01-26 10:07:48
【问题描述】:

在我的OData 控制器中,我有这样的方法:

// GET odata/Fixtures(5)
public SingleResult<Fixture> GetFixture([FromODataUri] int key)
{
    return SingleResult.Create(db.Fixtures.Where(fixture => fixture.FixtureId == key));
}

// GET odata/Fixtures(5)/City
[Queryable]
public SingleResult<City> GetCity([FromODataUri] int key)
{
    return SingleResult.Create(db.Fixtures.Where(m => m.FixtureId == key).Select(m => m.City));
}

// GET odata/Fixtures(5)/Team
[Queryable]
public SingleResult<Team> GetTeam([FromODataUri] int key)
{
    return SingleResult.Create(db.Fixtures.Where(m => m.FixtureId == key).Select(m => m.Team));
}

我如何从Fixtures 集合中获得AngularJs 的城市和团队?这没有得到他们:

<tbody>
    <tr ng-repeat="fixture in fixtures | orderBy:'FixtureId'" id="fixture_{{fixture.id}}">
        <td>{{fixture.FixtureId}}</td>
        <td>{{fixture.City.CityName}}</td>
        <td>{{fixture.Team.TeamName}}</td>
        ...
    </tr>
</tbody>

我是否需要在 GetFixture 中引用 GetCityGetTeam 才能返回类似于以下内容的 DTO:

class FixtureDTO
{
    public int FixtureId { get; set; }
    public string CityName { get; set; }
    public string TeamName { get; set; }
}

如果是这样,有人有我将如何做到这一点的例子吗?还是我完全以错误的方式处理这个问题?

任何建议将不胜感激!

【问题讨论】:

    标签: c# asp.net-mvc angularjs asp.net-web-api odata


    【解决方案1】:

    我使用 $expand odata 关键字在服务器对查询夹具的响应中包含导航属性。 这样做您的客户端代码必须工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-18
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多