private void FixupCustomerPicture(CustomerPicture previousValue) { // This is the principal end in an association that performs cascade deletes. // Update the event listener to refer to the new dependent. if (previousValue != null) { ChangeTracker.ObjectStateChanging -= previousValue.HandleCascadeDelete; } if (CustomerPicture != null) { ChangeTracker.ObjectStateChanging += CustomerPicture.HandleCascadeDelete; } if (IsDeserializing) { return; } if (previousValue != null && ReferenceEquals(previousValue.Customer, this)) { previousValue.Customer = null; } if (CustomerPicture != null) { CustomerPicture.Customer = this; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("CustomerPicture") && (ChangeTracker.OriginalValues["CustomerPicture"] == CustomerPicture)) { ChangeTracker.OriginalValues.Remove("CustomerPicture"); } else { ChangeTracker.RecordOriginalValue("CustomerPicture", previousValue); // This is the principal end of an identifying association, so the dependent must be deleted when the relationship is removed. // If the current state of the dependent is Added, the relationship can be changed without causing the dependent to be deleted. if (previousValue != null && previousValue.ChangeTracker.State != ObjectState.Added) { previousValue.MarkAsDeleted(); } } if (CustomerPicture != null && !CustomerPicture.ChangeTracker.ChangeTrackingEnabled) { CustomerPicture.StartTracking(); } } }
private void FixupCustomerPicture(CustomerPicture previousValue) { // This is the principal end in an association that performs cascade deletes. // Update the event listener to refer to the new dependent. if (previousValue != null) { ChangeTracker.ObjectStateChanging -= previousValue.HandleCascadeDelete; } if (CustomerPicture != null) { ChangeTracker.ObjectStateChanging += CustomerPicture.HandleCascadeDelete; } if (IsDeserializing) { return; } if (previousValue != null && ReferenceEquals(previousValue.Customer, this)) { previousValue.Customer = null; } if (CustomerPicture != null) { CustomerPicture.Customer = this; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("CustomerPicture") && (ChangeTracker.OriginalValues["CustomerPicture"] == CustomerPicture)) { ChangeTracker.OriginalValues.Remove("CustomerPicture"); } else { ChangeTracker.RecordOriginalValue("CustomerPicture", previousValue); // This is the principal end of an identifying association, so the dependent must be deleted when the relationship is removed. // If the current state of the dependent is Added, the relationship can be changed without causing the dependent to be deleted. if (previousValue != null && previousValue.ChangeTracker.State != ObjectState.Added) { previousValue.MarkAsDeleted(); } } if (CustomerPicture != null && !CustomerPicture.ChangeTracker.ChangeTrackingEnabled) { CustomerPicture.StartTracking(); } } }