Example #1
0
 private void ClearForeignKeyReferences(TrackedObject to)
 {
     foreach (MetaAssociation association in to.Type.Associations)
     {
         if ((association.IsForeignKey && (association.OtherMember != null)) && association.OtherMember.IsAssociation)
         {
             object[] foreignKeyValues = CommonDataServices.GetForeignKeyValues(association, to.Current);
             object   instance         = this.services.IdentityManager.Find(association.OtherType, foreignKeyValues);
             if (instance != null)
             {
                 if (association.OtherMember.Association.IsMany)
                 {
                     IList boxedValue = association.OtherMember.MemberAccessor.GetBoxedValue(instance) as IList;
                     if ((boxedValue != null) && !boxedValue.IsFixedSize)
                     {
                         boxedValue.Remove(to.Current);
                     }
                 }
                 else
                 {
                     association.OtherMember.MemberAccessor.SetBoxedValue(ref instance, null);
                 }
             }
         }
     }
 }
Example #2
0
 private bool HasAssociationChanged(MetaAssociation assoc, TrackedObject item)
 {
     if ((item.Original != null) && (item.Current != null))
     {
         if (assoc.ThisMember.StorageAccessor.HasAssignedValue(item.Current) || assoc.ThisMember.StorageAccessor.HasLoadedValue(item.Current))
         {
             return(this.GetOtherItem(assoc, item.Current) != this.GetOtherItem(assoc, item.Original));
         }
         object[] foreignKeyValues = CommonDataServices.GetForeignKeyValues(assoc, item.Current);
         object[] objArray2        = CommonDataServices.GetForeignKeyValues(assoc, item.Original);
         int      index            = 0;
         int      length           = foreignKeyValues.Length;
         while (index < length)
         {
             if (!object.Equals(foreignKeyValues[index], objArray2[index]))
             {
                 return(true);
             }
             index++;
         }
     }
     return(false);
 }
Example #3
0
        private TrackedObject GetOtherItem(MetaAssociation assoc, object instance)
        {
            object boxedValue;

            if (instance == null)
            {
                return(null);
            }
            if (assoc.ThisMember.StorageAccessor.HasAssignedValue(instance) || assoc.ThisMember.StorageAccessor.HasLoadedValue(instance))
            {
                boxedValue = assoc.ThisMember.MemberAccessor.GetBoxedValue(instance);
            }
            else
            {
                object[] foreignKeyValues = CommonDataServices.GetForeignKeyValues(assoc, instance);
                boxedValue = this.services.GetCachedObject(assoc.OtherType, foreignKeyValues);
            }
            if (boxedValue == null)
            {
                return(null);
            }
            return(this.tracker.GetTrackedObject(boxedValue));
        }