Export (0) Print
Expand All

ObjectStateManager.ChangeRelationshipState Method (Object, Object, String, String, EntityState)

Changes the state of the relationship between two entity objects that is specified based on the two related objects and the properties of the relationship.

Namespace:  System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public ObjectStateEntry ChangeRelationshipState(
	Object sourceEntity,
	Object targetEntity,
	string relationshipName,
	string targetRoleName,
	EntityState relationshipState
)

Parameters

sourceEntity
Type: System.Object
The object instance or EntityKey of the source entity at one end of the relationship.
targetEntity
Type: System.Object
The object instance or EntityKey of the target entity at the other end of the relationship.
relationshipName
Type: System.String
The name of the relationship.
targetRoleName
Type: System.String
The role name at the target end of the relationship.
relationshipState
Type: System.Data.EntityState
The requested EntityState of the specified relationship.

Return Value

Type: System.Data.Objects.ObjectStateEntry
The ObjectStateEntry for the relationship that was changed.

ExceptionCondition
ArgumentNullException

When source or target is null.

InvalidOperationException

When you try to change the state of the relationship to a state other than Deleted or Detached when either source or target is in a Deleted state.

-or-

When you try to change the state of the relationship to a state other than Added or Detached when either source or target is in an Added state.

-or-

When state is not a valid EntityState value.

Entries for the objects at both ends of the specified relationship must exist in the ObjectStateManager.

NoteNote

This method is not supported for relationships that are based on a foreign key association. For more information, see Defining and Managing Relationships

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft