private void DelayedFixup(InternalEntityEntry entry, INavigation navigation, InternalEntityEntry referencedEntry) { var navigationValue = entry[navigation]; if (navigationValue != null) { var setModified = referencedEntry.EntityState != EntityState.Unchanged && referencedEntry.EntityState != EntityState.Modified; if (!navigation.IsDependentToPrincipal()) { if (navigation.IsCollection()) { if (entry.CollectionContains(navigation, referencedEntry)) { FixupToDependent(entry, referencedEntry, navigation.ForeignKey, setModified); } } else if (referencedEntry.Entity == navigationValue) { FixupToDependent(entry, referencedEntry, navigation.ForeignKey, setModified); } } else if (referencedEntry.Entity == navigationValue) { FixupToPrincipal(entry, referencedEntry, navigation.ForeignKey, setModified); } } }