Esempio n. 1
0
 internal override void ClearCollectionOrRef(IEntityWrapper wrappedEntity, RelationshipNavigation navigation, bool doCascadeDelete)
 {
     if (null != _wrappedRelatedEntities)
     {
         //copy into list because changing collection member is not allowed during enumeration.
         // If possible avoid copying into list.
         var tempCopy = new List <IEntityWrapper>(_wrappedRelatedEntities.Values);
         foreach (var wrappedCurrent in tempCopy)
         {
             // Following condition checks if we have already visited this graph node. If its true then
             // we should not do fixup because that would cause circular loop
             if ((wrappedEntity.Entity == wrappedCurrent.Entity) &&
                 (navigation.Equals(RelationshipNavigation)))
             {
                 Remove(
                     wrappedCurrent, /*fixup*/ false, /*deleteEntity*/ false, /*deleteOwner*/ false, /*applyReferentialConstraints*/
                     false, /*preserveForeignKey*/ false);
             }
             else
             {
                 Remove(
                     wrappedCurrent, /*fixup*/ true, doCascadeDelete, /*deleteOwner*/ false, /*applyReferentialConstraints*/ false,
                     /*preserveForeignKey*/ false);
             }
         }
         Debug.Assert(
             _wrappedRelatedEntities.Count == 0, "After removing all related entities local collection count should be zero");
     }
 }
 internal override void ClearCollectionOrRef(
     IEntityWrapper wrappedEntity,
     RelationshipNavigation navigation,
     bool doCascadeDelete)
 {
     if (wrappedEntity == null)
     {
         wrappedEntity = NullEntityWrapper.NullWrapper;
     }
     if (this._wrappedCachedValue.Entity != null)
     {
         if (wrappedEntity.Entity == this._wrappedCachedValue.Entity && navigation.Equals((object)this.RelationshipNavigation))
         {
             this.Remove(this._wrappedCachedValue, false, false, false, false, false);
         }
         else
         {
             this.Remove(this._wrappedCachedValue, true, doCascadeDelete, false, true, false);
         }
     }
     else if (this.WrappedOwner.Entity != null && this.WrappedOwner.Context != null && !this.UsingNoTracking)
     {
         this.WrappedOwner.Context.ObjectStateManager.GetEntityEntry(this.WrappedOwner.Entity).DeleteRelationshipsThatReferenceKeys(this.RelationshipSet, this.ToEndMember);
     }
     if (this.WrappedOwner.Entity == null)
     {
         return;
     }
     this.DetachedEntityKey = (EntityKey)null;
 }
Esempio n. 3
0
        internal override void ClearCollectionOrRef(IEntityWrapper wrappedEntity, RelationshipNavigation navigation, bool doCascadeDelete)
        {
            if (wrappedEntity == null)
            {
                wrappedEntity = NullEntityWrapper.NullWrapper;
            }
            if (null != _wrappedCachedValue.Entity)
            {
                // Following condition checks if we have already visited this graph node. If its true then
                // we should not do fixup because that would cause circular loop
                if ((wrappedEntity.Entity == _wrappedCachedValue.Entity) &&
                    (navigation.Equals(RelationshipNavigation)))
                {
                    Remove(
                        _wrappedCachedValue, /*fixup*/ false, /*deleteEntity*/ false, /*deleteOwner*/ false, /*applyReferentialConstraints*/
                        false, /*preserveForeignKey*/ false);
                }
                else
                {
                    Remove(
                        _wrappedCachedValue, /*fixup*/ true, doCascadeDelete, /*deleteOwner*/ false, /*applyReferentialConstraints*/ true,
                        /*preserveForeignKey*/ false);
                }
            }
            else
            {
                // this entity reference could be replacing a relationship that points to a key entry
                // we need to search relationships on the Owner entity to see if this is true, and if so remove the relationship entry
                if (WrappedOwner.Entity != null &&
                    WrappedOwner.Context != null &&
                    !UsingNoTracking)
                {
                    var ownerEntry = WrappedOwner.Context.ObjectStateManager.GetEntityEntry(WrappedOwner.Entity);
                    ownerEntry.DeleteRelationshipsThatReferenceKeys(RelationshipSet, ToEndMember);
                }
            }

            // If we have an Owner, clear the DetachedEntityKey.
            // If we do not have an owner, retain the key so that we can resolve the difference when the entity is attached to a context
            if (WrappedOwner.Entity != null)
            {
                // Clear the detachedEntityKey as well. In cases where we have to fix up the detachedEntityKey, we will not always be able to detect
                // if we have *only* a Deleted relationship for a given entity/relationship/role, so clearing this here will ensure that
                // even if no other relationships are added, the key value will still be correct.
                DetachedEntityKey = null;
            }
        }
 internal override void ClearCollectionOrRef(
     IEntityWrapper wrappedEntity,
     RelationshipNavigation navigation,
     bool doCascadeDelete)
 {
     if (this._wrappedRelatedEntities == null)
     {
         return;
     }
     foreach (IEntityWrapper wrappedEntity1 in new List <IEntityWrapper>((IEnumerable <IEntityWrapper>) this._wrappedRelatedEntities.Values))
     {
         if (wrappedEntity.Entity == wrappedEntity1.Entity && navigation.Equals((object)this.RelationshipNavigation))
         {
             this.Remove(wrappedEntity1, false, false, false, false, false);
         }
         else
         {
             this.Remove(wrappedEntity1, true, doCascadeDelete, false, false, false);
         }
     }
 }