odata控制器。纠正为什么要通过键实现get

时间:2016-08-24 07:18:39

标签: odata

我从pluralsight课程改编了这种模式。因为能够返回正确的http代码。

public virtual IHttpActionResult Get(int key)
{
    IQueryable<T> result = Repository.AsQueryable().Where(p => p.Id == key);

    if (!result.Any())
        return NotFound();

    return Ok(SingleResult.Create(result));
}

问题在于返回格式。

{
   "@odata.context":"https://localhost:44300/odata/$metadata#Reports/$entity","Id":1,"Name":"Test Report#1","Description":"Min f\u00f8rste rapport","CategoryTypeId":1,"OrganizationId":1,"Definition":null,"AccessModifier":"Local","ObjectOwnerId":1,"LastChanged":"2016-08-18T12:57:48.3735722+02:00","LastChangedByUserId":1
}

它是同一个json对象中的上下文元数据和实体属性的混合。根据{{​​3}}它很难与之合作,没有任何问题。

有没有办法纠正这种行为?

1 个答案:

答案 0 :(得分:1)

如果您使用application/json; odata.metadata=none添加Accept标头,则会删除元数据。