ObjectStateManager.ChangeRelationshipState 方法 (Object, Object, String, EntityState)
[本页针对的是实体框架版本 6。最新版本以“实体框架”NuGet 包的形式提供。有关实体框架的更多信息,请参见 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 | 当 source 或 target 为 null 时。 |
InvalidOperationException | 当您尝试在 source 或 target 处于 Deleted 状态时将关系的状态更改为 Deleted 或 Detached 以外的状态时,或当您尝试在 source 或 target 处于 Added 状态时将关系的状态更改为 Added 或 Detached 以外的状态时,或当状态为无效的 EntityState 值时。 |