包括带的WebAPI的OData请求相关的实体实体、WebAPI、OData

2023-09-03 17:38:25 作者:假装你还在i

有没有什么办法,包括在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:您的服务需要支持 $展开 $选择