使用WCF数据服务,是否可以在联合表上使用$expand命令
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多对多关系通常由服务通过隐藏连接表来建模(如果它存储的唯一内容是关系并且其中没有数据)。如果您在服务中使用 EF,这应该很容易做到。
如果由于某种原因您确实需要公开连接表,那么您可以发出如下查询:(
扩展可以是多个级别)。当然,由于存在两个级别,读取结果会稍微复杂一些,但您确实获得了所需的数据。
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:
(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.