Metodo ObjectStateManager.ChangeRelationshipState<TEntity> (TEntity, Object, Expression<Func<TEntity, Object>>, EntityState)
[Questa pagina è specifica della versione 6 di Entity Framework. La versione più recente è disponibile come pacchetto NuGet per "Entity Framework". Per ulteriori informazioni su Entity Framework, vedere la pagina msdn.com/data/ef.]
Modifica lo stato della relazione tra due oggetti entità specificata in base ai due oggetti correlati e a un'espressione LINQ che definisce la proprietà di navigazione.
Spazio dei nomi: System.Data.Entity.Core.Objects
Assembly: EntityFramework (in EntityFramework.dll)
Sintassi
'Dichiarazione
<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")> _
Public Overridable 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
'Utilizzo
Dim instance As ObjectStateManager
Dim sourceEntity As TEntity
Dim targetEntity As Object
Dim navigationPropertySelector As Expression(Of Func(Of TEntity, Object))
Dim relationshipState As EntityState
Dim returnValue As ObjectStateEntry
returnValue = instance.ChangeRelationshipState(sourceEntity, _
targetEntity, navigationPropertySelector, _
relationshipState)
[SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
public virtual ObjectStateEntry ChangeRelationshipState<TEntity>(
TEntity sourceEntity,
Object targetEntity,
Expression<Func<TEntity, Object>> navigationPropertySelector,
EntityState relationshipState
)
where TEntity : class
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1006:DoNotNestGenericTypesInMemberSignatures")]
public:
generic<typename TEntity>
where TEntity : ref class
virtual ObjectStateEntry^ ChangeRelationshipState(
TEntity sourceEntity,
Object^ targetEntity,
Expression<Func<TEntity, Object^>^>^ navigationPropertySelector,
EntityState relationshipState
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
abstract ChangeRelationshipState :
sourceEntity:'TEntity *
targetEntity:Object *
navigationPropertySelector:Expression<Func<'TEntity, Object>> *
relationshipState:EntityState -> ObjectStateEntry when 'TEntity : not struct
[<SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")>]
override ChangeRelationshipState :
sourceEntity:'TEntity *
targetEntity:Object *
navigationPropertySelector:Expression<Func<'TEntity, Object>> *
relationshipState:EntityState -> ObjectStateEntry when 'TEntity : not struct
JScript does not support generic types and methods.
Parametri di tipo
- TEntity
Tipo di entità dell'oggetto di origine.
Parametri
- sourceEntity
Tipo: TEntity
Istanza dell'oggetto o EntityKey dell'entità di origine a un'estremità della relazione.
- targetEntity
Tipo: System.Object
Istanza dell'oggetto o EntityKey dell'entità di destinazione all'altra estremità della relazione.
- navigationPropertySelector
Tipo: System.Linq.Expressions.Expression<Func<TEntity, Object>>
Espressione LINQ che seleziona la proprietà di navigazione dell'origine che restituisce la destinazione specificata.
- relationshipState
Tipo: System.Data.Entity.EntityState
Oggetto EntityState richiesto della relazione specificata.
Valore restituito
Tipo: System.Data.Entity.Core.Objects.ObjectStateEntry
ObjectStateEntry per la relazione modificata.
Eccezioni
Eccezione | Condizione |
---|---|
ArgumentNullException | Quando source, target o selector è Null. |
ArgumentException | selector è in un formato non valido o non può restituire una proprietà di navigazione. |
InvalidOperationException | Quando si tenta di modificare lo stato della relazione impostandolo su uno stato diverso da Deleted o Detached quando l'origine o la destinazione si trova in uno stato Deleted o quando si tenta di modificare lo stato della relazione impostandolo su uno stato diverso da Added o Detached quando l'origine o la destinazione si trova in uno stato Added o quando lo stato non è un valore EntityState valido. |