使用WCF数据服务,是否可以在联合表上使用$expand命令

发布于 2024-10-01 23:52:01 字数 474 浏览 3 评论 0原文

我正在尝试使用 WCF 数据服务做一些相当容易理解的事情,但找不到如何做。

我有 3 个表,Customer、Product 和一个连接其他两个表的联合表 Customer_Product(基本的 n 到 n 关系): 客户 <= Customer_Product =>产品

我想在同一查询中获取客户及其产品,因此我想做类似的操作:

/Service.svc/Customers(23)?$expand=Products

但它告诉我表 Customer 上没有 Products 导航属性。

我发现的唯一选择是:

/Service.svc/Customers(23)?$expand=Customer_Product

然后再次拨打电话以获取产品详细信息。

有没有一种干净的方法来做到这一点?

预先非常感谢。

I am trying to do something fairly easy to understand with WCF data services, but can't find how to do it.

I have 3 table, Customer, Product and a joint table Customer_Product linking the two other tables (a basic n to n relationship):
Customer <= Customer_Product => Product

I want to get a customer and its products in the same query, so I would like to do something like:

/Service.svc/Customers(23)?$expand=Products

But it tells me that there is no Products navigation property on the table Customer.

The only option that I found is to do:

/Service.svc/Customers(23)?$expand=Customer_Product

and then make another call to get the Product details.

Is there a clean way to do this?

Thanks a lot in advance.

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

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

发布评论

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

评论(1

那小子欠揍 2024-10-08 23:52:01

多对多关系通常由服务通过隐藏连接表来建模(如果它存储的唯一内容是关系并且其中没有数据)。如果您在服务中使用 EF,这应该很容易做到。
如果由于某种原因您确实需要公开连接表,那么您可以发出如下查询:(

/Service.svc/Customers(23)?$expand=Customer_Product/Product

扩展可以是多个级别)。当然,由于存在两个级别,读取结果会稍微复杂一些,但您确实获得了所需的数据。

The many to many relationships are usually modeled by the service by hiding the join table (if the only thing it stores is the relationship and there's no data in it). If you're using EF in the service this should be pretty easy to do.
If you do need to expose the join table for some reason, then you can issue a query like:

/Service.svc/Customers(23)?$expand=Customer_Product/Product

(expands can be multiple levels deep). Of course reading the results will be a bit more complicated because of the two levels there, but you do get the data you need.

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