ObjectStateManager.ChangeRelationshipState 方法 (Object, Object, String, EntityState)
[此頁面專屬於 Entity Framework 第 6 版。最新版本可從 'Entity Framework' NuGet 套件取得。如需 Entity Framework 的詳細資訊,請參閱 msdn.com/data/ef。]
變更兩個實體物件之間關聯性的狀態,其中的關聯性狀態是依據兩個相關物件和巡覽屬性名稱而指定的。
命名空間: System.Data.Entity.Core.Objects
組件: EntityFramework (在 EntityFramework.dll 中)
語法
'宣告
Public Overridable Function ChangeRelationshipState ( _
sourceEntity As Object, _
targetEntity As Object, _
navigationProperty As String, _
relationshipState As EntityState _
) As ObjectStateEntry
'用途
Dim instance As ObjectStateManager
Dim sourceEntity As Object
Dim targetEntity As Object
Dim navigationProperty As String
Dim relationshipState As EntityState
Dim returnValue As ObjectStateEntry
returnValue = instance.ChangeRelationshipState(sourceEntity, _
targetEntity, navigationProperty, _
relationshipState)
public virtual ObjectStateEntry ChangeRelationshipState(
Object sourceEntity,
Object targetEntity,
string navigationProperty,
EntityState relationshipState
)
public:
virtual ObjectStateEntry^ ChangeRelationshipState(
Object^ sourceEntity,
Object^ targetEntity,
String^ navigationProperty,
EntityState relationshipState
)
abstract ChangeRelationshipState :
sourceEntity:Object *
targetEntity:Object *
navigationProperty:string *
relationshipState:EntityState -> ObjectStateEntry
override ChangeRelationshipState :
sourceEntity:Object *
targetEntity:Object *
navigationProperty:string *
relationshipState:EntityState -> ObjectStateEntry
public function ChangeRelationshipState(
sourceEntity : Object,
targetEntity : Object,
navigationProperty : String,
relationshipState : EntityState
) : ObjectStateEntry
參數
- sourceEntity
類型:System.Object
位於關聯性其中一端之來源實體的物件執行個體或 EntityKey。
- targetEntity
類型:System.Object
位於關聯性另一端之目標實體的物件執行個體或 EntityKey。
- navigationProperty
類型:System.String
傳回指定目標之來源的導覽屬性名稱。
- relationshipState
類型:System.Data.Entity.EntityState
指定之關聯性的要求 EntityState。
傳回值
類型:System.Data.Entity.Core.Objects.ObjectStateEntry
已變更之關聯性的 ObjectStateEntry。
例外狀況
例外狀況 | 條件 |
---|---|
ArgumentNullException | 當來源或目標為 null 時。 |
InvalidOperationException | 當來源或目標的狀態為 Deleted 時,嘗試將關聯性的狀態變更為 Deleted 或 Detached 以外的值;或者當來源或目標的狀態為 Added 時,嘗試將關聯性的狀態變更為 Added 或 Detached 以外的值;或者當狀態不是有效的 EntityState 值時 |