ObjectStateManager::ChangeRelationshipState Method (Object^, Object^, String^, EntityState)

.NET Framework (current version)
 

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

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

public:
ObjectStateEntry^ ChangeRelationshipState(
	Object^ sourceEntity,
	Object^ targetEntity,
	String^ navigationProperty,
	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.

navigationProperty
Type: System::String^

The name of the navigation property on source that returns the specified target.

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.

Exception Condition
ArgumentNullException

When source or target is null.

InvalidOperationException

When trying 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.

System_CAPS_noteNote

This method is not supported for relationships based on a foreign key association.

.NET Framework
Available since 4.0
Return to top
Show: