views:

334

answers:

2

I am using ADO.Net Data Services and have a Service Operation that ends up returning the results of some linq to entities statements. As a part of those Linq statements there is a .Include("NavProp") to include a sub-object. When running this service operation it doesn't appear to return that expanded Include. Does anyone know either why that is or how to fix that? Is it possible to add a keyword in the call to the service operation to expand that sub-object? (I tried $expand=subObject but that doesn't seem to work - bad request).

I'd like to end up with either: 1.) syntax for a linq statement in a service operation that returns the .Include also (i'm pretty sure this isn't possible)

something like:
(from c in context.MyObj.Include("SubObj")
select c).ToList()
(this works inside the service operation, but doesn't provide the SubObj on the client side)

or

2.) syntax for the service operation request to expand the subObject

something like: http://localhost/MyDataService/MyDataService.svc/ServiceOp1?param1=234$expand=SubObj (note: this doesn't work)
A: 

It looks like this is not possible at present (.net 3.5 SP1). Service Operations will only return either primative types or entities. Any other type including custom types or expanded entities cannot be returned from a service operation. To deal with this one must just return the item(s) from the service operation and then if an include/expand is needed on the client side one must call "LoadProperty" for the desired object expansion (note: this means another database hit per LoadProperty call).

ChrisHDog
+1  A: 

Having emailed MS on this issue, the solution is to use the expand query option on the uri of the service operation. For example,

.../<ServiceOperationName>.svc?$expand=<Property1Name>,<Property2Name> ...

Service Operation: GetCustomer
Relationship Property to load: Address
Uri: .../<GetCustomer>.svc?$expand=Address

Hope this helps.

Javed