包括带的WebAPI的OData请求相关的实体 [英] Include related entities with WebAPI OData request

查看:186
本文介绍了包括带的WebAPI的OData请求相关的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法,包括在OData的请求相关的实体?

Is there any way to include related entities in an OData request?

例如,我有一个Person实体和任务实体。的关系是1对多,与具有许多任务一个人。如果我查询数据的OData的要求:

For example, I have a Person entity and a Task entity. The relationship is one-to-many, with a Person having many Tasks. If I query the data with the OData request:

/odata/Person

让所有的人实体,JSON的返回不包括每个人的任务属性。

to get all the Person entities, the json returned does not include a Tasks property for each Person.

不过,如果我查询到的数据与OData的要求:

However, if I query the data with the OData request:

/odata/Person(14)/Tasks

我得到的任务属于该人的集合。

I get the collection of Tasks that belong to that Person.

什么,我希望能够做的就是让所有任务的所有人员的实体时,我让我的/ ODATA /人的请求。

What I'm hoping to be able to do is get ALL of the Tasks for all of the Person entities when I make my /odata/Person request.

推荐答案

尝试

/odata/Person?$expand=Tasks

将扩大在各实体的人的导航属性任务。如果你只想查询任务,不需要其他的属性,你可以试试:

it will expand the navigation property "Tasks" in each entity person. If you want to only query Tasks, do not need other properties, you can try:

/odata/Person?$select=Tasks&$expand=Tasks

PS:您的服务需要支持 $展开 $选择

这篇关于包括带的WebAPI的OData请求相关的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆