开发者

With WCF Data Services, is it possible to use the $expand command on joint tables

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, C开发者_StackOverflowustomer, 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜