Wednesday, January 22, 2014

Nested entities won't return in RIA Services

Such stupid things we waste time on!  I had a RIA service which was supposed to return some entities and their entity-based properties.  My troubleshooting clearly showed the entities being present in the service but none of the included entity properties arrived at the client filled out.  Fiddler proved that these entities weren't being serialized.  So where were they?  The problem was that it was an Invoke operation.  I guess I didn't fully understand the difference between Invoke and Load operations.  Very important!

An Invoke operation is intended to return scalar or single-Entity values.  In fact, it can even return a collection of Entities, but it specifically won't return nested properties.  It makes sense when you realize that by definition, Invoke operations don't return tracked entities.  Returning a fully populated object graph without the tracking is seldom something you really want.  Unfortunately, I had to switch into calling two service methods: one to do some entity creation, then a second call to retrieve the created objects as a complete graph.  Clearly not super difficult, but until you realize the limitation you just bang your head against the wall!

No comments:

Post a Comment