DataServiceContext.SetLink(Object, String, Object) Method

Definition

Notifies the DataServiceContext that a new link exists between the objects specified and that the link is represented by the property specified by the sourceProperty parameter.

public virtual void SetLink (object source, string sourceProperty, object target);
abstract member SetLink : obj * string * obj -> unit
override this.SetLink : obj * string * obj -> unit
Public Overridable Sub SetLink (source As Object, sourceProperty As String, target As Object)

Parameters

source
Object

The source object for the new link.

sourceProperty
String

The property on the source object that identifies the target object of the new link.

target
Object

The child object involved in the new link that is to be initialized by calling this method. The target object must be a subtype of the type identified by the sourceProperty parameter. If target is set to null, the call represents a delete link operation.

Exceptions

When source, sourceProperty or target are null.

When the specified link already exists.-or-When the objects supplied as source or target are in the Detached or Deleted state.-or-When sourceProperty is not a navigation property that defines a reference to a single related object.

Remarks

Notifies the context that a modified link exists between the source and target objects and that the link is represented via the source.sourceProperty which is a reference. The context adds this link to the set of modified created links to be sent to the data service on the next call to SaveChanges(). Links are one way relationships. If a back pointer exists (ie. two way association), this method should be called a second time to notify the context object of the second link.

Applies to