Share via


EntityReference.EntityKey Property

Definition

Returns the key for the related object.

[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

Property Value

An EntityKey that is the key of the related object.

Attributes

Remarks

Returns the EntityKey of the target entity associated with this EntityReference. Is non-null in the following scenarios: (a) Entities are tracked by a context and an Unchanged or Added client-side relationships exists for this EntityReference's owner with the same RelationshipName and source role. This relationship could have been created explicitly by the user (e.g. by setting the EntityReference.Value, setting this property directly, or by calling EntityCollection.Add) or automatically through span queries. (b) If the EntityKey was non-null before detaching an entity from the context, it will still be non-null after detaching, until any operation occurs that would set it to null, as described below. (c) Entities are detached and the EntityKey is explicitly set to non-null by the user. (d) Entity graph was created using a NoTracking query with full span Is null in the following scenarios: (a) Entities are tracked by a context but there is no Unchanged or Added client-side relationship for this EntityReference's owner with the same RelationshipName and source role. (b) Entities are tracked by a context and a relationship exists, but the target entity has a temporary key (i.e. it is Added) or the key is one of the special keys (c) Entities are detached and the relationship was explicitly created by the user.

Applies to