private void FixupCustomer(Customer previousValue)
        {
            // This is the dependent end in an association that performs cascade deletes.
            // Update the principal's event listener to refer to the new dependent.
            // This is a unidirectional relationship from the dependent to the principal, so the dependent end is
            // responsible for managing the cascade delete event handler. In all other cases the principal end will manage it.
            if (previousValue != null)
            {
                previousValue.ChangeTracker.ObjectStateChanging -= HandleCascadeDelete;
            }

            if (Customer != null)
            {
                Customer.ChangeTracker.ObjectStateChanging += HandleCascadeDelete;
            }

            if (IsDeserializing)
            {
                return;
            }

            if (Customer != null)
            {
                ContactID = Customer.ContactID;
            }

            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("Customer") &&
                    (ChangeTracker.OriginalValues["Customer"] == Customer))
                {
                    ChangeTracker.OriginalValues.Remove("Customer");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("Customer", previousValue);
                    // This is the dependent end of an identifying association, so it must be deleted when the relationship is
                    // removed. If the current state is Added, the relationship can be changed without causing the dependent to be deleted.
                    // This is a unidirectional relationship from the dependent to the principal, so the dependent end is
                    // responsible for cascading the delete. In all other cases the principal end will manage it.
                    if (previousValue != null && ChangeTracker.State != ObjectState.Added)
                    {
                        this.MarkAsDeleted();
                    }
                }
                if (Customer != null && !Customer.ChangeTracker.ChangeTrackingEnabled)
                {
                    Customer.StartTracking();
                }
            }
        }
Пример #2
0
        private void FixupCustomer(Customer previousValue)
        {
            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && previousValue.Reservations.Contains(this))
            {
                previousValue.Reservations.Remove(this);
            }

            if (Customer != null)
            {
                if (!Customer.Reservations.Contains(this))
                {
                    Customer.Reservations.Add(this);
                }

                ContactID = Customer.ContactID;
            }
            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("Customer") &&
                    (ChangeTracker.OriginalValues["Customer"] == Customer))
                {
                    ChangeTracker.OriginalValues.Remove("Customer");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("Customer", previousValue);
                }
                if (Customer != null && !Customer.ChangeTracker.ChangeTrackingEnabled)
                {
                    Customer.StartTracking();
                }
            }
        }