private void ConditionallyNullForeignKeyProperties( InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey) { var principalProperties = foreignKey.PrincipalKey.Properties; var dependentProperties = foreignKey.Properties; var hasOnlyKeyProperties = true; if (principalEntry != null && principalEntry.EntityState != EntityState.Detached) { for (var i = 0; i < foreignKey.Properties.Count; i++) { if (!PrincipalValueEqualsDependentValue( principalProperties[i], dependentEntry[dependentProperties[i]], principalEntry[principalProperties[i]])) { return; } if (!dependentProperties[i].IsKey()) { hasOnlyKeyProperties = false; } } } for (var i = 0; i < foreignKey.Properties.Count; i++) { if (!dependentProperties[i].IsKey()) { dependentEntry[dependentProperties[i]] = null; dependentEntry.StateManager.UpdateDependentMap(dependentEntry, foreignKey); dependentEntry.SetRelationshipSnapshotValue(dependentProperties[i], null); } } if (foreignKey.IsRequired && hasOnlyKeyProperties && dependentEntry.EntityState != EntityState.Detached) { switch (dependentEntry.EntityState) { case EntityState.Added: dependentEntry.SetEntityState(EntityState.Detached); DeleteFixup(dependentEntry); break; case EntityState.Unchanged: case EntityState.Modified: dependentEntry.SetEntityState(EntityState.Deleted); DeleteFixup(dependentEntry); break; } } }