Creating Associations Between Objects in ADO.NET Data Services
Data services expose resources (entities) and links (associations). When
we generate a .NET client proxy the links (associations) are built as properties
of the objects. When we associate an object to another object we have to
explicitly tell the proxy to add the association. This is being done by the
SetLink method which is exposed through the generated client proxy.
The SetLink method notifies the DataServiceContext that a new link exists
between the objects it gets as parameters and to which property the link will
be generated. If you will try to insert an object to an association property and
won’t use the SetLink method you should expect an exception.
Create Association Example
In the example, there is an association between course and department.
departments can hold many courses and a course is associated to a specific
department. As you can see I set the Department property of course to be
the first department and then I have to explicitly call the SetLink method and
to indicate the property name (Department) in order to set the link.
Currently Implementation Problems
In the Using Microsoft ADO.NET Data Services article it is indicated that the
currently data services implementation “is designed for minimum footprint and
provides the primitives required to enable mapping data service operations to
.NET objects. For a future release, we are evaluating layering higher level semantics”.
This means that managing modifications to arbitrary object graphs with bidirectional
associations isn’t fully supported right now but will be supported in future releases.
Lets sum up, I showed in the post that to set an association between two associated
objects is done by using the SetLink method. You need to explicitly call that method
in order to establish the connection between the objects. Not calling that method will
result in an exception. Currently the data services framework is supporting the
minimum functionality to enable mapping but in future releases we should expect
the ability to manage modifications to arbitrary object graphs with bidirectional