/// <summary> /// Clean up. /// </summary> /// <param name="disposing"> /// True if called from Dispose, false if called from the finalizer. /// </param> private void Dispose(bool disposing) { // No unmanaged resources so disposing is unused if (!_disposed) { _current = _parent; _disposed = true; } }
/// <summary> /// Creata a new <see cref="CacheContext"/> from /// an existing set of entities. /// </summary> /// <param name="contextType"> /// Whether this is a new or attached context. /// </param> /// <exception cref="ArgumentException"> /// <paramref name="contextType"/> is unknown or invalid. /// </exception> internal CacheContext(ContextType contextType) { ContextType = contextType; _parent = _current; if (contextType == ContextType.New) { _entry = new CacheContextEntry(); if (_parent != null) { _entry.Entities.ItemsAdded += (o, e) => _parent.Entities.Add(e.Items); _entry.RelationshipTypes.ItemsAdded += (o, e) => _parent.RelationshipTypes.Add(e.Items); _entry.FieldTypes.ItemsAdded += (o, e) => _parent.FieldTypes.Add(e.Items); _entry.EntityInvalidatingRelationshipTypes.ItemsAdded += (o, e) => _parent.EntityInvalidatingRelationshipTypes.Add(e.Items); _entry.EntityTypes.ItemsAdded += (o, e) => _parent.EntityTypes.Add(e.Items); } } else if (contextType == ContextType.Attached) { _entry = _current; } else if (contextType == ContextType.Detached) { _entry = new CacheContextEntry(); } else if (contextType == ContextType.None) { _entry = null; } else { throw new ArgumentException("Unknown contextType", "contextType"); } // Placed last incase exception is thrown in constructor. _current = _entry; }