Esempio n. 1
0
 internal override void Exclude()
 {
     if (null != _wrappedRelatedEntities && null != this.ObjectContext)
     {
         if (!IsForeignKey)
         {
             foreach (IEntityWrapper wrappedEntity in _wrappedRelatedEntities.Values)
             {
                 ExcludeEntity(wrappedEntity);
             }
         }
         else
         {
             TransactionManager tm = ObjectContext.ObjectStateManager.TransactionManager;
             Debug.Assert(tm.IsAddTracking || tm.IsAttachTracking, "Exclude being called while not part of attach/add rollback--PromotedEntityKeyRefs will be null.");
             List <IEntityWrapper> values = new List <IEntityWrapper>(_wrappedRelatedEntities.Values);
             foreach (IEntityWrapper wrappedEntity in values)
             {
                 EntityReference otherEnd = GetOtherEndOfRelationship(wrappedEntity) as EntityReference;
                 Debug.Assert(otherEnd != null, "Other end of FK from a collection should be a reference.");
                 bool doFullRemove       = tm.PopulatedEntityReferences.Contains(otherEnd);
                 bool doRelatedEndRemove = tm.AlignedEntityReferences.Contains(otherEnd);
                 if (doFullRemove || doRelatedEndRemove)
                 {
                     // Remove the related ends and mark the relationship as deleted, but don't propagate the changes to the target entity itself
                     otherEnd.Remove(otherEnd.CachedValue,
                                     doFixup: doFullRemove,
                                     deleteEntity: false,
                                     deleteOwner: false,
                                     applyReferentialConstraints: false,
                                     preserveForeignKey: true);
                     // Since this has been processed, remove it from the list
                     if (doFullRemove)
                     {
                         tm.PopulatedEntityReferences.Remove(otherEnd);
                     }
                     else
                     {
                         tm.AlignedEntityReferences.Remove(otherEnd);
                     }
                 }
                 else
                 {
                     ExcludeEntity(wrappedEntity);
                 }
             }
         }
     }
 }