Beispiel #1
0
        // Records a removal to collection valued properties on SelfTracking Entities.
        internal void RecordRemovalFromCollectionProperties(string propertyName, object value)
        {
            if (_changeTrackingEnabled)
            {
                // Delete the entity back after adding it, we should do nothing here then
                if (ObjectsAddedToCollectionProperties.ContainsKey(propertyName) &&
                    ObjectsAddedToCollectionProperties[propertyName].Contains(value))
                {
                    ObjectsAddedToCollectionProperties[propertyName].Remove(value);
                    if (ObjectsAddedToCollectionProperties[propertyName].Count == 0)
                    {
                        ObjectsAddedToCollectionProperties.Remove(propertyName);
                    }
                    return;
                }

                if (!ObjectsRemovedFromCollectionProperties.ContainsKey(propertyName))
                {
                    ObjectsRemovedFromCollectionProperties[propertyName] = new ObjectList();
                    ObjectsRemovedFromCollectionProperties[propertyName].Add(value);
                }
                else
                {
                    if (!ObjectsRemovedFromCollectionProperties[propertyName].Contains(value))
                    {
                        ObjectsRemovedFromCollectionProperties[propertyName].Add(value);
                    }
                }
            }
        }
Beispiel #2
0
 // Resets the ObjectChangeTracker to the Unchanged state and
 // clears the original values as well as the record of changes
 // to collection properties
 public void AcceptChanges()
 {
     OnObjectStateChanging(ObjectState.Unchanged);
     OriginalValues.Clear();
     ModifiedValues.Clear();
     ObjectsAddedToCollectionProperties.Clear();
     ObjectsRemovedFromCollectionProperties.Clear();
     ChangeTrackingEnabled = true;
     _objectState          = ObjectState.Unchanged;
 }
Beispiel #3
0
        // Resets the ObjectChangeTracker to the Unchanged state and
        // sets the actual values to be the original values as well as the record of changes
        // to collection properties
        public void CancelChanges(IObjectWithChangeTracker entity)
        {
            if (this.State == ObjectState.Added)
            {
                return;
            }

            OnObjectStateChanging(ObjectState.Unchanged);
            ChangeTrackingEnabled = false;

            ModifiedValues.Clear();

            var originalValues = OriginalValues.ToArray();

            foreach (var kvp in originalValues)
            {
                string propertyName  = kvp.Key;
                object propertyValue = kvp.Value;

                entity.SetPropertyValue(propertyName, propertyValue);
            }

            var objectsAddedToCollectionProperties = ObjectsAddedToCollectionProperties.ToArray();

            foreach (var kvp in objectsAddedToCollectionProperties)
            {
                var propertyName = kvp.Key;
                var items        = kvp.Value;

                foreach (var item in items.ToArray())
                {
                    entity.RemoveItemFromCollection(propertyName, item);
                }
            }
            ObjectsAddedToCollectionProperties.Clear();

            var objectsRemovedFromCollectionProperties = ObjectsRemovedFromCollectionProperties.ToArray();

            foreach (var kvp in objectsRemovedFromCollectionProperties)
            {
                var propertyName = kvp.Key;
                var items        = kvp.Value;

                foreach (var item in items.ToArray())
                {
                    entity.AddItemToCollection(propertyName, item);
                }
            }
            ObjectsRemovedFromCollectionProperties.Clear();

            ChangeTrackingEnabled = true;
            _objectState          = ObjectState.Unchanged;
        }