private void FixupSalesPerson(SalesPerson previousValue, bool skipKeys = false) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.SalesOrderHeaders.Contains(this)) { previousValue.SalesOrderHeaders.Remove(this); } if (SalesPerson != null) { if (!SalesPerson.SalesOrderHeaders.Contains(this)) { SalesPerson.SalesOrderHeaders.Add(this); } SalesPersonID = SalesPerson.SalesPersonID; } else if (!skipKeys) { SalesPersonID = null; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("SalesPerson") && (ChangeTracker.OriginalValues["SalesPerson"] == SalesPerson)) { ChangeTracker.OriginalValues.Remove("SalesPerson"); } else { ChangeTracker.RecordOriginalValue("SalesPerson", previousValue); } if (SalesPerson != null && !SalesPerson.ChangeTracker.ChangeTrackingEnabled) { SalesPerson.StartTracking(); } } }
private void FixupSalesPerson(SalesPerson 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 (SalesPerson != null) { ChangeTracker.ObjectStateChanging += SalesPerson.HandleCascadeDelete; } if (IsDeserializing) { return; } if (previousValue != null && ReferenceEquals(previousValue.Employee, this)) { previousValue.Employee = null; } if (SalesPerson != null) { SalesPerson.Employee = this; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("SalesPerson") && (ChangeTracker.OriginalValues["SalesPerson"] == SalesPerson)) { ChangeTracker.OriginalValues.Remove("SalesPerson"); } else { ChangeTracker.RecordOriginalValue("SalesPerson", 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 (SalesPerson != null && !SalesPerson.ChangeTracker.ChangeTrackingEnabled) { SalesPerson.StartTracking(); } } }