Επεξεργασία

Κοινή χρήση μέσω


ObjectStateManager.ChangeRelationshipState Method

Definition

Changes the state of the specified relationship between two entity objects.

Overloads

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

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

ChangeRelationshipState<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.

Remarks

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

ChangeRelationshipState(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:
 System::Data::Objects::ObjectStateEntry ^ ChangeRelationshipState(System::Object ^ sourceEntity, System::Object ^ targetEntity, System::String ^ navigationProperty, System::Data::EntityState relationshipState);
public System.Data.Objects.ObjectStateEntry ChangeRelationshipState (object sourceEntity, object targetEntity, string navigationProperty, System.Data.EntityState relationshipState);
member this.ChangeRelationshipState : obj * obj * string * System.Data.EntityState -> System.Data.Objects.ObjectStateEntry
Public Function ChangeRelationshipState (sourceEntity As Object, targetEntity As Object, navigationProperty As String, relationshipState As EntityState) As ObjectStateEntry

Parameters

sourceEntity
Object

The object instance or EntityKey of the source entity at one end of the relationship.

targetEntity
Object

The object instance or EntityKey of the target entity at the other end of the relationship.

navigationProperty
String

The name of the navigation property on sourceEntity that returns the specified targetEntity.

relationshipState
EntityState

The requested EntityState of the specified relationship.

Returns

The ObjectStateEntry for the relationship that was changed.

Exceptions

When source or target is null.

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.

Remarks

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

Note

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

Applies to

ChangeRelationshipState(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:
 System::Data::Objects::ObjectStateEntry ^ ChangeRelationshipState(System::Object ^ sourceEntity, System::Object ^ targetEntity, System::String ^ relationshipName, System::String ^ targetRoleName, System::Data::EntityState relationshipState);
public System.Data.Objects.ObjectStateEntry ChangeRelationshipState (object sourceEntity, object targetEntity, string relationshipName, string targetRoleName, System.Data.EntityState relationshipState);
member this.ChangeRelationshipState : obj * obj * string * string * System.Data.EntityState -> System.Data.Objects.ObjectStateEntry
Public Function ChangeRelationshipState (sourceEntity As Object, targetEntity As Object, relationshipName As String, targetRoleName As String, relationshipState As EntityState) As ObjectStateEntry

Parameters

sourceEntity
Object

The object instance or EntityKey of the source entity at one end of the relationship.

targetEntity
Object

The object instance or EntityKey of the target entity at the other end of the relationship.

relationshipName
String

The name of the relationship.

targetRoleName
String

The role name at the targetEntity end of the relationship.

relationshipState
EntityState

The requested EntityState of the specified relationship.

Returns

The ObjectStateEntry for the relationship that was changed.

Exceptions

When source or target is null.

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.

Remarks

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

Note

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

Applies to

ChangeRelationshipState<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.

public:
generic <typename TEntity>
 where TEntity : class System::Data::Objects::ObjectStateEntry ^ ChangeRelationshipState(TEntity sourceEntity, System::Object ^ targetEntity, System::Linq::Expressions::Expression<Func<TEntity, System::Object ^> ^> ^ navigationPropertySelector, System::Data::EntityState relationshipState);
public System.Data.Objects.ObjectStateEntry ChangeRelationshipState<TEntity> (TEntity sourceEntity, object targetEntity, System.Linq.Expressions.Expression<Func<TEntity,object>> navigationPropertySelector, System.Data.EntityState relationshipState) where TEntity : class;
member this.ChangeRelationshipState : 'Entity * obj * System.Linq.Expressions.Expression<Func<'Entity, obj>> * System.Data.EntityState -> System.Data.Objects.ObjectStateEntry (requires 'Entity : null)
Public Function ChangeRelationshipState(Of TEntity As Class) (sourceEntity As TEntity, targetEntity As Object, navigationPropertySelector As Expression(Of Func(Of TEntity, Object)), relationshipState As EntityState) As ObjectStateEntry

Type Parameters

TEntity

The entity type of the sourceEntity object.

Parameters

sourceEntity
TEntity

The object instance or EntityKey of the source entity at one end of the relationship.

targetEntity
Object

The object instance or EntityKey of the target entity at the other end of the relationship.

navigationPropertySelector
Expression<Func<TEntity,Object>>

A LINQ expression that selects the navigation property on sourceEntity that returns the specified targetEntity.

relationshipState
EntityState

The requested EntityState of the specified relationship.

Returns

The ObjectStateEntry for the relationship that was changed.

Exceptions

When source, target, or selector is null.

selector is malformed or cannot return a navigation property.

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.

Remarks

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

Note

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

Applies to