Exemplo n.º 1
0
        /// <summary>
        /// Adds an entity type shape to the diagram
        /// </summary>
        /// <param name="entityType">Model entity type to add to the diagram.</param>
        /// <returns>An EntityTypeShape object</returns>
        public EntityTypeShape AddEntityTypeShape(ModelEntityType entityType)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }

            EntityTypeShape ets = EntityTypeShapes.FirstOrDefault(es => es.EntityType == entityType);

            if (ets == null)
            {
                ets          = new EntityTypeShape(ParentFile, this, entityType);
                ets.Removed += new EventHandler(ets_Removed);
                _entityTypeShapes.Add(ets.EntityTypeName, ets);
            }
            return(ets);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Return true if there is diagram object that represents efelement/efobject in the diagram.
        /// </summary>
        /// <param name="efObject"></param>
        /// <returns></returns>
        internal bool IsEFObjectRepresentedInDiagram(EFObject efObject)
        {
            var entityTypesInDiagram = EntityTypeShapes.Select(ets => ets.EntityType.Target).ToList();

            var entityType     = efObject.GetParentOfType(typeof(ConceptualEntityType)) as ConceptualEntityType;
            var association    = efObject.GetParentOfType(typeof(Association)) as Association;
            var associationSet = efObject as AssociationSet;
            var entitySet      = efObject as EntitySet;

            // if efobject is an associationset, check if the corresponding association is in the diagram.
            if (associationSet != null &&
                associationSet.Association.Status == BindingStatus.Known)
            {
                association = associationSet.Association.Target;
            }

            // if efobject is an entity-set, Return true only if all the entity-types contained in the set are represented in the diagram.
            if (entitySet != null)
            {
                foreach (var et in entitySet.GetEntityTypesInTheSet())
                {
                    if (entityTypesInDiagram.Contains(et) == false)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            else if (entityType != null)
            {
                return(entityTypesInDiagram.Contains(entityType));
            }
            else if (association != null)
            {
                var associationsInDiagram = AssociationConnectors.Select(a => a.Association.Target).ToList();
                return(associationsInDiagram.Contains(association));
            }
            return(false);
        }