ObjectStateManager.ChangeRelationshipState 方法 (Object, Object, String, 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, _
relationshipName As String, _
targetRoleName As String, _
relationshipState As EntityState _
) As ObjectStateEntry
'用途
Dim instance As ObjectStateManager
Dim sourceEntity As Object
Dim targetEntity As Object
Dim relationshipName As String
Dim targetRoleName As String
Dim relationshipState As EntityState
Dim returnValue As ObjectStateEntry
returnValue = instance.ChangeRelationshipState(sourceEntity, _
targetEntity, relationshipName, _
targetRoleName, relationshipState)
public virtual ObjectStateEntry ChangeRelationshipState(
Object sourceEntity,
Object targetEntity,
string relationshipName,
string targetRoleName,
EntityState relationshipState
)
public:
virtual ObjectStateEntry^ ChangeRelationshipState(
Object^ sourceEntity,
Object^ targetEntity,
String^ relationshipName,
String^ targetRoleName,
EntityState relationshipState
)
abstract ChangeRelationshipState :
sourceEntity:Object *
targetEntity:Object *
relationshipName:string *
targetRoleName:string *
relationshipState:EntityState -> ObjectStateEntry
override ChangeRelationshipState :
sourceEntity:Object *
targetEntity:Object *
relationshipName:string *
targetRoleName:string *
relationshipState:EntityState -> ObjectStateEntry
public function ChangeRelationshipState(
sourceEntity : Object,
targetEntity : Object,
relationshipName : String,
targetRoleName : String,
relationshipState : EntityState
) : ObjectStateEntry
參數
- sourceEntity
類型:System.Object
位於關聯性其中一端之來源實體的物件執行個體或 EntityKey。
- targetEntity
類型:System.Object
位於關聯性另一端之目標實體的物件執行個體或 EntityKey。
- relationshipName
類型:System.String
關聯性的名稱。
- targetRoleName
類型: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 值時 |