语言

EntityReference.EntityKey 属性

定义

返回相关对象的键。

[System.Runtime.Serialization.DataMember]
public System.Data.Entity.Core.EntityKey EntityKey { get; set; }
member this.EntityKey : System.Data.Entity.Core.EntityKey with get, set
Public Property EntityKey As EntityKey

属性值

一个 EntityKey 是相关对象的键。

特性

注解

返回与此 EntityReference 关联的目标实体的 EntityKey。 在以下方案中为非 null:(a) 实体由上下文跟踪,并且此 EntityReference 的所有者存在具有相同 RelationshipName 和源角色的未更改或已添加的客户端关系。 此关系可由用户显式创建(例如,通过设置 EntityReference.Value、直接设置此属性,或通过调用 EntityCollection.Add)或通过跨度查询自动创建。 (b) 如果在从上下文中分离实体之前 EntityKey 为非 null,则在分离后它仍将为非 null,直到发生任何将它设置为 null 的操作,如下所示。 (c) 实体被分离,并且 EntityKey 被用户显式设置为非 null。 (d) 实体图是在以下情况下使用全跨度为 null 的 NoTracking 查询创建的:(a) 实体由上下文跟踪,但此 EntityReference 的所有者没有具有相同 RelationshipName 和源角色的未更改或添加的客户端关系。 (b) 实体由上下文跟踪并存在关系,但目标实体具有临时键(即已添加),或者密钥是分离的特殊键(c)实体之一,并且关系由用户显式创建。

适用于