views:

14

answers:

1

I am learning WCF data services (cannot upgrade to RIA) and one of the major benefits I thougth I would get was that it would maintain relations for me and do lazy loads...

Example:

A bidirectional relation:

Order.Items --> OrderItems
OrderItem.Order --> Order

Say I have already a reference to an order. Then I populate its items by calling BeginLoadProperty(order, "OrderItems"). After that I would expect that the following would be true:

order.OrderItems[0].Order == order;

Unfortunatelly order.OrderItems[0].Order is null...

Is this scenario supported? Will it WCF data services handle for you? Or are you left with your custom implementation?

I use Entity Framework as the underlying data service.

Thanks!

A: 

WCF Data Services doesn't do lazy loading for several reasons. One is that most users want complete control of when a web request is made (as it can be very expensive) and second sometimes it's not technically possible. For example in Silverlight all HTTP requests can be done only through asynchronous API and as such lazy load can't really be implemented since accessing a property is a synchronous operation. As to your question: The WCF Data Services client doesn't know about bidirectional relations. It sees it as two separate relations. So it can't fixup the links for you. For this to work you could built the knowledge of bidirectional relations into your client side entities (for example your Orders property can fixup the back link when items are added into it). The other possible solution would be to use more complex queries using the $expand query option to load the parent entity in the same request. Unfortunately the LoadProperty/BeginLoadProperty API doesn't support extending the query this way, you would have to construct the query yourself. So to answer you last question, you are left with your custom implementation.

Vitek Karas MSFT