src/Shared/EntityFramework/Core/Objects/DataClasses/EntityReference.cs
// <summary>
// This method is called when either the EntityKey or the Value property is set to null when it is
// already null. For an FK association of a tracked entity the method will attempt to null FKs
// thereby deleting the relationship. This may result in conceptual nulls being set.
// </summary>
This method is called when either the EntityKey or the Value property is set to null when it is
already null. For an FK association of a tracked entity the method will attempt to null FKs
thereby deleting the relationship. This may result in conceptual nulls being set.
This method is called when either the EntityKey or the Value property is set to null when it is already null . For an FK association of a tracked entity the method will attempt to null FKs thereby deleting the relationship . This may result in conceptual nulls being set .
internal bool AttemptToNullFKsOnRefOrKeySetToNull()
        {
            if (ReferenceValue.Entity == null
                &&
                WrappedOwner.Entity != null
                &&
                WrappedOwner.Context != null
                &&
                !UsingNoTracking
                &&
                IsForeignKey)
            {
                if (WrappedOwner.ObjectStateEntry.State != EntityState.Added
                    &&
                    IsDependentEndOfReferentialConstraint(checkIdentifying: true))
                {
                    throw new InvalidOperationException(Strings.EntityReference_CannotChangeReferentialConstraintProperty);
                }
                RemoveFromLocalCache(NullEntityWrapper.NullWrapper, resetIsLoaded: true, preserveForeignKey: false);
                return true;
            }
            return false;
        }
internal bool AttemptToNullFKsOnRefOrKeySetToNull ( ) { if ( ReferenceValue . Entity == null && WrappedOwner . Entity != null && WrappedOwner . Context != null && ! UsingNoTracking && IsForeignKey ) { if ( WrappedOwner . ObjectStateEntry . State != EntityState . Added && IsDependentEndOfReferentialConstraint ( checkIdentifying : true ) ) { throw new InvalidOperationException ( Strings . EntityReference_CannotChangeReferentialConstraintProperty ) ; } RemoveFromLocalCache ( NullEntityWrapper . NullWrapper , resetIsLoaded : true , preserveForeignKey : false ) ; return true ; } return false ; }
This method is called when either the EntityKey or the Value property is set to null when it is
already null.
This method is called when either the EntityKey or the Value property is set to null when it is already null .
// For identifying relationships, we throw, since we cannot set primary key values to null, unless // the entity is in the Added state. // For unloaded FK relationships in the context we attempt to null FK values here, which will // delete the relationship.