src/Shared/EntityFramework/Core/Objects/DataClasses/EntityReference.cs
// <summary>Adds to navigation property if compatible.</summary>
// <param name="otherRelatedEnd">The related end to add.</param>
Adds to navigation property if compatible.
Adds to navigation property if compatible .
internal override void AddToNavigationPropertyIfCompatible(RelatedEnd otherRelatedEnd)
        {
            if (NavigationPropertyIsNullOrMissing())
            {
                AddToNavigationProperty(otherRelatedEnd.WrappedOwner);
                Debug.Assert(otherRelatedEnd.ObjectContext != null, "Expected attached context at this point.");
                var cacheEntry = otherRelatedEnd.ObjectContext.ObjectStateManager.FindEntityEntry(otherRelatedEnd.WrappedOwner.Entity);
                if (cacheEntry != null
                    &&
                    otherRelatedEnd.ObjectContext.ObjectStateManager.TransactionManager.IsAddTracking
                    &&
                    otherRelatedEnd.IsForeignKey
                    &&
                    IsDependentEndOfReferentialConstraint(checkIdentifying: false))
                {
                    MarkForeignKeyPropertiesModified();
                }
            }
            else if (!CheckIfNavigationPropertyContainsEntity(otherRelatedEnd.WrappedOwner))
            {
                throw Error.ObjectStateManager_ConflictingChangesOfRelationshipDetected(
                    RelationshipNavigation.To,
                    RelationshipNavigation.RelationshipName);
            }
        }
internal override void AddToNavigationPropertyIfCompatible ( RelatedEnd otherRelatedEnd ) { if ( NavigationPropertyIsNullOrMissing ( ) ) { AddToNavigationProperty ( otherRelatedEnd . WrappedOwner ) ; Debug . Assert ( otherRelatedEnd . ObjectContext != null , " " ) ; var cacheEntry = otherRelatedEnd . ObjectContext . ObjectStateManager . FindEntityEntry ( otherRelatedEnd . WrappedOwner . Entity ) ; if ( cacheEntry != null && otherRelatedEnd . ObjectContext . ObjectStateManager . TransactionManager . IsAddTracking && otherRelatedEnd . IsForeignKey && IsDependentEndOfReferentialConstraint ( checkIdentifying : false ) ) { MarkForeignKeyPropertiesModified ( ) ; } } else if ( ! CheckIfNavigationPropertyContainsEntity ( otherRelatedEnd . WrappedOwner ) ) { throw Error . ObjectStateManager_ConflictingChangesOfRelationshipDetected ( RelationshipNavigation . To , RelationshipNavigation . RelationshipName ) ; } }
Adds to navigation property if compatible.
Adds to navigation property if compatible .
// If this end is non-null, then don't overwrite it. // If it's non-null and doesn't match what we think it should be, then throw. // If the other end is a dependent that is already tracked, then we need to make sure // its FK props are marked as modified even though we are not fixing them up.
otherRelatedEnd
RelatedEnd
The related end to add.
The related end to add .