src/Shared/EntityFramework/Core/Objects/DataClasses/EntityReference.cs
// <summary>
// Ensures the detached entity key is valid (not temporary etc.) 
// </summary>
Ensures the detached entity key is valid (not temporary etc.)
Ensures the detached entity key is valid ( not temporary etc . )
internal override void ValidateDetachedEntityKey()
        {
            if (IsEmpty()
                && DetachedEntityKey != null)
            {
                var detachedKey = DetachedEntityKey;
                if (!IsValidEntityKeyType(detachedKey))
                {
                    throw Error.EntityReference_CannotSetSpecialKeys();
                }
                var targetEntitySet = detachedKey.GetEntitySet(ObjectContext.MetadataWorkspace);
                CheckRelationEntitySet(targetEntitySet);
                detachedKey.ValidateEntityKey(ObjectContext.MetadataWorkspace, targetEntitySet);
            }
        }
internal override void ValidateDetachedEntityKey ( ) { if ( IsEmpty ( ) && DetachedEntityKey != null ) { var detachedKey = DetachedEntityKey ; if ( ! IsValidEntityKeyType ( detachedKey ) ) { throw Error . EntityReference_CannotSetSpecialKeys ( ) ; } var targetEntitySet = detachedKey . GetEntitySet ( ObjectContext . MetadataWorkspace ) ; CheckRelationEntitySet ( targetEntitySet ) ; detachedKey . ValidateEntityKey ( ObjectContext . MetadataWorkspace , targetEntitySet ) ; } }
Ensures the detached entity key is valid (not temporary etc.)
Ensures the detached entity key is valid ( not temporary etc . )
// If this is a stub EntityReference and the DetachedEntityKey is set, make sure it is valid // devnote: We have to check this here instead of in the EntityKey property setter, //          because the key could be set to an invalid type temporarily during deserialization // else even for a reference we don't need to validate the key // because it will be checked later once we have the key for the contained entity