Пример #1
0
        public void RemoveChild(Entity entity)
        {
            if (!children.Contains(entity))
            {
                return;
            }

            children.Remove(entity);
            entity.Parent = null;

            // Add the ID property back to the child entity
            for (int i = entity.Key.Properties.ToList().Count - 1; i >= 0; i--)
            {
                if (entity.Properties.Count(p => p == entity.Key.Properties.ElementAt(i)) == 0)
                {
                    entity.AddProperty(entity.Key.Properties.ElementAt(i));
                }
            }
            // Add any hidden properties back to the child
            foreach (var hiddenProperty in entity.PropertiesHiddenByAbstractParent)
            {
                hiddenProperty.IsHiddenByAbstractParent = false;
            }

            foreach (var hiddenProperty in entity.PropertiesInHiddenKey)
            {
                hiddenProperty.IsPartOfHiddenKey = false;
            }

            // Add references back between removed child and its parent, which was removed when creating the inheritance structure.
            if (entity.MappedTables().Count() > 0 && this.MappedTables().Count() > 0 &&
                entity.DirectedReferences.Count(d => d.ToEntity == this) == 0)
            {
                var thisTable  = this.MappedTables().ElementAt(0);
                var childTable = entity.MappedTables().ElementAt(0);

                foreach (Relationship rel in thisTable.Relationships.Where(r => (r.ForeignTable == thisTable && r.PrimaryTable == childTable) || (r.ForeignTable == childTable && r.PrimaryTable == thisTable)))
                {
                    ArchAngel.Providers.EntityModel.Controller.MappingLayer.MappingProcessor.ProcessRelationshipInternal(entity.EntitySet.MappingSet, rel, new ArchAngel.Providers.EntityModel.Controller.MappingLayer.OneToOneEntityProcessor());
                }
            }
            ChildrenChanged.RaiseDeletionEventEx(this, entity);
        }