src/Shared/EntityFramework/Core/Objects/DataClasses/EntityReference.cs
// <summary>Verifies the detached key matches of the entity key.</summary>
// <param name="entityKey">The key entity.</param>
Verifies the detached key matches of the entity key.
Verifies the detached key matches of the entity key .
internal override void VerifyDetachedKeyMatches(EntityKey entityKey)
        {
            if (DetachedEntityKey != null)
            {
                var targetKey = entityKey;
                if (DetachedEntityKey != targetKey)
                {
                    if (targetKey.IsTemporary)
                    {
                        throw Error.RelatedEnd_CannotCreateRelationshipBetweenTrackedAndNoTrackedEntities(RelationshipNavigation.To);
                    }
                    throw new InvalidOperationException(Strings.EntityReference_EntityKeyValueMismatch);
                }
            }
        }
internal override void VerifyDetachedKeyMatches ( EntityKey entityKey ) { if ( DetachedEntityKey != null ) { var targetKey = entityKey ; if ( DetachedEntityKey != targetKey ) { if ( targetKey . IsTemporary ) { throw Error . RelatedEnd_CannotCreateRelationshipBetweenTrackedAndNoTrackedEntities ( RelationshipNavigation . To ) ; } throw new InvalidOperationException ( Strings . EntityReference_EntityKeyValueMismatch ) ; } } }
Verifies the detached key matches of the entity key.
Verifies the detached key matches of the entity key .
// If we have a reference with a detached key, make sure the key matches the relationship we are about to add // Check for the case where a NoTracking (with detached entity key) is being Added and throw the same // exception we do elsewhere for this case. // We might consider changing this behavior in the future to just put the entity in the Added state, // but for consistency for now we throw the same exception as elsewhere. // else -- null just means the key isn't set, so the target entity key doesn't also have to be null
entityKey
EntityKey
The key entity.
The key entity .