ObjectStateManager.ChangeRelationshipState Method

 

Changes state of a relationship between two entities.

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

NameDescription
System_CAPS_pubmethodChangeRelationshipState(Object, Object, String, EntityState)

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.

System_CAPS_pubmethodChangeRelationshipState(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.

System_CAPS_pubmethodChangeRelationshipState<TEntity>(TEntity, Object, Expression<Func<TEntity, Object>>, EntityState)

Changes the state of the relationship between two entity objects that is specified based on the two related objects and a LINQ expression that defines the navigation property.


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

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.

public virtual 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.Entity.EntityState

The requested EntityState of the specified relationship.

Return Value

Type: System.Data.Entity.Core.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


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.

public virtual 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.Entity.EntityState

The requested EntityState of the specified relationship.

Return Value

Type: System.Data.Entity.Core.Objects.ObjectStateEntry

The ObjectStateEntry for the relationship that was changed.

Exception Condition
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.


ObjectStateManager.ChangeRelationshipState<TEntity> Method (TEntity, Object, Expression<Func<TEntity, Object>>, EntityState)

Changes the state of the relationship between two entity objects that is specified based on the two related objects and a LINQ expression that defines the navigation property.

[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public virtual ObjectStateEntry ChangeRelationshipState<TEntity>(
	TEntity sourceEntity,
	object targetEntity,
	Expression<Func<TEntity, object>> navigationPropertySelector,
	EntityState relationshipState
)
where TEntity : class

Parameters

sourceEntity
Type: TEntity

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.

navigationPropertySelector
Type: System.Linq.Expressions.Expression<Func<TEntity, Object>>

A LINQ expression that selects the navigation property on source that returns the specified target .

relationshipState
Type: System.Data.Entity.EntityState

The requested EntityState of the specified relationship.

Return Value

Type: System.Data.Entity.Core.Objects.ObjectStateEntry

The ObjectStateEntry for the relationship that was changed.

Type Parameters

TEntity

The entity type of the source object.

Exception Condition
ArgumentNullException

When source , target , or selector is null.

ArgumentException

selector is malformed or cannot return a navigation property.

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.