是否可以查询 Odata 服务并展开子实体的子实体?

发布于 2024-11-29 13:43:29 字数 613 浏览 0 评论 0原文

这听起来相当简单(也许我在这里错过了显而易见的事情),但我找不到解决方案。我知道我可以查询一个实体并返回一个或多个直接子实体来执行此操作:

var query = from c in Service.Clients.Expand("Addresses,Comments,PhoneNumbers")..

我希望能够做的是对 3 个级别(子级的子级)执行相同的操作,可以说“国家 -> 省 - >城市”或“品牌->家庭->模型”

我尝试扩展所有实体,但失败了

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

有没有办法在一个查询中执行此操作,或者我是否必须将其拆分为两个单独的查询?

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")..

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感性不性感 2024-12-06 13:43:29

在 ASP.NET OData v4 中,URL 约定似乎发生了变化。现在是:

~/Brands?$expand=Families($expand=Models)

您还可以在子实体中选择您想要的内容。
例如,如果您只想要品牌系列标识符:

~/Brands?$expand=Families($select=Id)

此外,如果您只想要品牌系列型号的标识符,您可以这样做:

~/Brands?$expand=Families($expand=Models($select=Id))

...等等。希望这有帮助!

In ASP.NET OData v4, the URL convention seems to have changed. It is now:

~/Brands?$expand=Families($expand=Models)

You can also select the stuff you want in sub-entities.
For example if you want just the brand family identifiers:

~/Brands?$expand=Families($select=Id)

Furthermore, if you want only the identifiers of the brand family models, you would do that:

~/Brands?$expand=Families($expand=Models($select=Id))

...and so on. Hope this helps !

凑诗 2024-12-06 13:43:29

以下语句应返回您要查找的内容:

var query = from c in Service.Brands.Expand("Families/Models")

这将运行以下 odata 查询:

.../OData.svc/Brands?$expand=Families/Models

此处是一些其他 odata 文档的链接:

$expand 查询选项的语法是逗号分隔的导航属性列表。此外,每个导航属性后面都可以跟一个正斜杠和另一个导航属性,以识别多级关系。

The following statement should return what you are looking for:

var query = from c in Service.Brands.Expand("Families/Models")

This will run the following odata query:

.../OData.svc/Brands?$expand=Families/Models

Here is a link to some further odata documentation:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文