Example #1
0
        private void FixupStore(Store 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 (Store != null)
            {
                ChangeTracker.ObjectStateChanging += Store.HandleCascadeDelete;
            }

            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && ReferenceEquals(previousValue.Customer, this))
            {
                previousValue.Customer = null;
            }

            if (Store != null)
            {
                Store.Customer = this;
            }

            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("Store")
                    && (ChangeTracker.OriginalValues["Store"] == Store))
                {
                    ChangeTracker.OriginalValues.Remove("Store");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("Store", 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 (Store != null && !Store.ChangeTracker.ChangeTrackingEnabled)
                {
                    Store.StartTracking();
                }
            }
        }
Example #2
0
        private void FixupStore(Store previousValue)
        {
            if (IsDeserializing)
            {
                return;
            }

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

            if (Store != null)
            {
                if (!Store.StoreContacts.Contains(this))
                {
                    Store.StoreContacts.Add(this);
                }

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