是否可以查询Odata服务并展开Child of Child实体? [英] is it possible to Query an Odata service and expand Child of Child entities?
问题描述
这听起来很简单(也许我在这里没有找到明显的答案),但是我找不到解决方案.我知道我可以查询一个实体并返回一个或多个直接子实体来执行此操作:
This sounds rather simple (and maybe I'm missing the obvious here) but I can't find a solution. I know I can query an entity and return one, or many direct child entities doing this:
var query = from c in Service.Clients.Expand("Addresses,Comments,PhoneNumbers")..
我想做的是对3个级别(孩子的孩子)做同样的事情,让我们说国家->省->城市"或品牌->家庭->模型"
What I would like to be able to do is do the same with 3 levels (Children of child), lets say "Country->Province->City" or "Brand->Family->Model"
我尝试扩展所有实体,但是失败
I tried to expand all entities, but it fails
var query = from c in Service.Brands.Expand("Families,Models").. //fails,
//which even makes some sense, since Models is a Child of Family, not Brand
var query = from c in Service.Brands.Expand("Families").. //this works,
//but Family.Models is empty
是否可以在一个查询中执行此操作,还是必须将其拆分为两个单独的查询?
Is there a way to do this in one query, or do I have to split this in two separate queries?
推荐答案
以下语句应返回您要查找的内容:
The following statement should return what you are looking for:
var query = from c in Service.Brands.Expand("Families/Models")
这将运行以下odata查询:
This will run the following odata query:
.../OData.svc/Brands?$expand=Families/Models
此处是一些其他odata文档的链接:
Here is a link to some further odata documentation:
$ expand查询选项的语法是导航属性的逗号分隔列表.此外,每个导航属性后面都可以有一个正斜杠和另一个导航属性,以实现标识多级关系.
The syntax of a $expand query option is a comma-separated list of Navigation Properties. Additionally each Navigation Property can be followed by a forward slash and another Navigation Property to enable identifying a multi-level relationship.
这篇关于是否可以查询Odata服务并展开Child of Child实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!