コード例 #1
0
        /// <summary>
        /// Compares this instance to a given Navigation by their values.
        /// </summary>
        public override bool Equals(object obj)
        {
            RelationshipNavigation compareTo = obj as RelationshipNavigation;

            return((this == compareTo) ||
                   ((null != this) && (null != compareTo) &&
                    (this.RelationshipName == compareTo.RelationshipName) &&
                    (this.From == compareTo.From) &&
                    (this.To == compareTo.To)));
        }
コード例 #2
0
        internal override void ClearCollectionOrRef(IEntityWrapper wrappedEntity, RelationshipNavigation navigation, bool doCascadeDelete)
        {
            if (wrappedEntity == null)
            {
                wrappedEntity = EntityWrapperFactory.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(this.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)
                {
                    EntityEntry ownerEntry = WrappedOwner.Context.ObjectStateManager.GetEntityEntry(WrappedOwner.Entity);
                    ownerEntry.DeleteRelationshipsThatReferenceKeys(this.RelationshipSet, this.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 (this.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.
                ((EntityReference)this).DetachedEntityKey = null;
            }
        }
コード例 #3
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.
         List <IEntityWrapper> tempCopy = new List <IEntityWrapper>(_wrappedRelatedEntities.Values);
         foreach (IEntityWrapper 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");
     }
 }
コード例 #4
0
 internal EntityReference(IEntityWrapper wrappedOwner, RelationshipNavigation navigation, IRelationshipFixer relationshipFixer)
     : base(wrappedOwner, navigation, relationshipFixer)
 {
     _wrappedCachedValue = EntityWrapperFactory.NullWrapper;
 }
コード例 #5
0
 internal EntityReference(IEntityWrapper wrappedOwner, RelationshipNavigation navigation, IRelationshipFixer relationshipFixer)
     : base(wrappedOwner, navigation, relationshipFixer)
 {
 }
コード例 #6
0
 internal EntityCollection(IEntityWrapper wrappedOwner, RelationshipNavigation navigation, IRelationshipFixer relationshipFixer)
     : base(wrappedOwner, navigation, relationshipFixer)
 {
 }
コード例 #7
0
 internal EntityReference(IEntityWrapper wrappedOwner, RelationshipNavigation navigation, IRelationshipFixer relationshipFixer)
     : base(wrappedOwner, navigation, relationshipFixer)
 {
 }
コード例 #8
0
 /// <summary>
 /// Used during relationship fixup when the source end of the relationship is not
 /// yet in the relationships list, and needs to be created
 /// </summary>
 /// <param name="navigation">RelationshipNavigation to be set on new RelatedEnd</param>
 /// <param name="relationshipManager">RelationshipManager to use for creating the new end</param>
 /// <returns>Reference to the new collection or reference on the other end of the relationship</returns>
 RelatedEnd IRelationshipFixer.CreateSourceEnd(RelationshipNavigation navigation, RelationshipManager relationshipManager)
 {
     return(relationshipManager.CreateRelatedEnd <TTargetEntity, TSourceEntity>(navigation, _targetRoleMultiplicity, _sourceRoleMultiplicity, /*existingRelatedEnd*/ null));
 }