Example #1
0
 internal override void SaveDiagram(
     SerializationResult serializationResult, EntityDesignerDiagram diagram, string diagramFileName, Encoding encoding,
     bool writeOptionalPropertiesWithDefaultValue)
 {
     // don't save the .diagram file
     return;
 }
        /// <summary>
        ///     This method will return a DSL ShapeElement for the given efobject.  If the given efobject doesn't map to a designer shape,
        ///     then this will look for a designer shape for the object's parent.
        ///     If no designer shape can be found, this will return null.
        /// </summary>
        /// <param name="efobject"></param>
        /// <returns></returns>
        private static ShapeElement GetDesignerShapeElementForEFObject(EntityDesignerDiagram diagram, EFObject efobject)
        {
            ShapeElement shapeElement = null;

            while (shapeElement == null &&
                   efobject != null &&
                   ((efobject is ConceptualEntityModel) == false))
            {
                var dslElement = diagram.ModelElement.ModelXRef.GetExisting(efobject);
                shapeElement = dslElement as ShapeElement;

                if (shapeElement == null &&
                    dslElement != null)
                {
                    var shapes = PresentationViewsSubject.GetPresentation(dslElement);

                    // just select the first shape for this item
                    if (shapes != null &&
                        shapes.Count > 0)
                    {
                        shapeElement = shapes[0] as ShapeElement;
                    }
                }

                // walk up the EFObject tree until we find a node that has a ShapeElement.
                if (shapeElement == null)
                {
                    efobject = efobject.Parent;
                }
            }
            return(shapeElement);
        }
        internal static void StaticInvoke(CommandProcessorContext cpc, EntityDesignerDiagram diagram)
        {
            var viewModel = diagram.ModelElement;

            Debug.Assert(viewModel != null, "Why Diagram's Model Element is null?");

            if (viewModel != null)
            {
                var artifact = cpc.Artifact;
                Debug.Assert(artifact != null && artifact.DesignerInfo() != null && artifact.DesignerInfo().Diagrams != null);
                if (artifact != null &&
                    artifact.DesignerInfo() != null &&
                    artifact.DesignerInfo().Diagrams != null)
                {
                    var modelDiagram = CreateDiagramCommand.CreateDiagramWithDefaultName(cpc);
                    Debug.Assert(modelDiagram != null);
                    using (var t = diagram.Store.TransactionManager.BeginTransaction("Set Diagram Id", false))
                    {
                        diagram.DiagramId = modelDiagram.Id.Value;
                        t.Commit();
                    }
                    viewModel.ModelXRef.Add(modelDiagram, diagram, viewModel.EditingContext);
                }
            }
        }
Example #4
0
        internal override EntityDesignerDiagram CreateDiagramHelper(Partition diagramPartition, ModelElement modelRoot)
        {
            var evm     = modelRoot as EntityDesignerViewModel;
            var diagram = new EntityDesignerDiagram(diagramPartition);

            diagram.ModelElement = evm;
            return(diagram);
        }
Example #5
0
        internal static void CreateDefaultDiagram(EditingContext context, EntityDesignerDiagram diagram)
        {
            var service  = context.GetEFArtifactService();
            var artifact = service.Artifact;

            Debug.Assert(artifact != null, "Artifact is null");

            var cpc = new CommandProcessorContext(
                context, EfiTransactionOriginator.EntityDesignerOriginatorId, EntityDesignerResources.Tx_CreateDiagram);
            var cmd = new DelegateCommand(
                () =>
            {
                EntityDesignerDiagramAdd.StaticInvoke(cpc, diagram);

                foreach (var shapeElement in diagram.NestedChildShapes)
                {
                    var entityShape = shapeElement as EntityTypeShape;
                    if (entityShape != null)
                    {
                        EntityTypeShapeAdd.StaticInvoke(cpc, entityShape);
                        EntityTypeShapeChange.StaticInvoke(
                            cpc, entityShape, ViewModelDiagram.NodeShape.AbsoluteBoundsDomainPropertyId);
                        EntityTypeShapeChange.StaticInvoke(cpc, entityShape, ViewModelDiagram.NodeShape.IsExpandedDomainPropertyId);
                        continue;
                    }

                    var associationConnector = shapeElement as AssociationConnector;
                    if (associationConnector != null)
                    {
                        AssociationConnectorAdd.StaticInvoke(cpc, associationConnector);
                        AssociationConnectorChange.StaticInvoke(
                            cpc, associationConnector, ViewModelDiagram.LinkShape.EdgePointsDomainPropertyId);
                        AssociationConnectorChange.StaticInvoke(
                            cpc, associationConnector, ViewModelDiagram.LinkShape.ManuallyRoutedDomainPropertyId);
                        continue;
                    }

                    var inheritanceConnector = shapeElement as InheritanceConnector;
                    if (inheritanceConnector != null)
                    {
                        InheritanceConnectorAdd.StaticInvoke(cpc, inheritanceConnector);
                        InheritanceConnectorChange.StaticInvoke(
                            cpc, inheritanceConnector, ViewModelDiagram.LinkShape.EdgePointsDomainPropertyId);
                        InheritanceConnectorChange.StaticInvoke(
                            cpc, inheritanceConnector, ViewModelDiagram.LinkShape.ManuallyRoutedDomainPropertyId);
                        continue;
                    }
                }
            });

            CommandProcessor.InvokeSingleCommand(cpc, cmd);
        }
        internal static void ExportAsImage(EntityDesignerDiagram diagram)
        {
            if (diagram != null)
            {
                using (var dlg = new SaveFileDialog())
                {
                    dlg.Title            = Resources.ExportAsImageTitle;
                    dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    dlg.Filter           = Resources.ImageFormatBmp + "|*.bmp|" +
                                           Resources.ImageFormatJpeg + "|*.jpg|" +
                                           Resources.ImageFormatGif + "|*.gif|" +
                                           Resources.ImageFormatPng + "|*.png|" +
                                           Resources.ImageFormatTiff + "|*.tif";
                    dlg.FileName = Resources.ExportImage_DefaultFileName;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        var childShapes = diagram.NestedChildShapes;
                        Debug.Assert(childShapes != null && childShapes.Count > 0, "Diagram '" + diagram.Title + "' is empty");

                        if (childShapes != null &&
                            childShapes.Count > 0)
                        {
                            var bmp = diagram.CreateBitmap(childShapes, Diagram.CreateBitmapPreference.FavorSmallSizeOverClarity);

                            var imageFormat = ImageFormat.Bmp;
                            var fi          = new FileInfo(dlg.FileName);
                            if (fi.Extension.Equals(".jpg", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Jpeg;
                            }
                            else if (fi.Extension.Equals(".gif", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Gif;
                            }
                            else if (fi.Extension.Equals(".png", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Png;
                            }
                            else if (fi.Extension.Equals(".tif", StringComparison.OrdinalIgnoreCase))
                            {
                                imageFormat = ImageFormat.Tiff;
                            }

                            using (var fs = new FileStream(dlg.FileName, FileMode.Create, FileAccess.ReadWrite))
                            {
                                bmp.Save(fs, imageFormat);
                            }
                        }
                    }
                }
            }
        }
        private EntityDesignerDiagram GetNewOrExistingViewDiagram()
        {
            EntityDesignerDiagram diagram = null;

            // Check whether the EntityDesignerDiagram exists.
            var docData = DocData as MicrosoftDataEntityDesignDocDataBase;

            diagram = GetExistingViewDiagram(docData, _diagramId);

            // Create DSL diagram if the diagram has not been created yet.
            if (diagram == null &&
                String.IsNullOrEmpty(_diagramId) == false)
            {
                var artifact = Context.GetEFArtifactService().Artifact as EntityDesignArtifact;
                Debug.Assert(artifact != null, "Could not find instance of EntityDesignArtifact in EditingContext.");
                if (artifact != null)
                {
                    if (artifact.IsDesignerSafe &&
                        artifact.DesignerInfo != null &&
                        artifact.DesignerInfo.Diagrams != null)
                    {
                        // Get the corresponding model diagram.
                        var modelDiagram = artifact.DesignerInfo.Diagrams.GetDiagram(_diagramId);
                        if (modelDiagram != null)
                        {
                            using (var transaction = docData.Store.TransactionManager.BeginTransaction("OpenView", true))
                            {
                                var evm =
                                    ModelTranslatorContextItem.GetEntityModelTranslator(Context)
                                    .TranslateModelToDslModel(modelDiagram, new DslModeling.Partition(docData.Store)) as
                                    EntityDesignerViewModel;
                                diagram = CreateDslDiagram(evm);
                                transaction.Commit();
                            }
                        }
                    }
                    else
                    {
                        using (var transaction = docData.Store.TransactionManager.BeginTransaction("OpenView", true))
                        {
                            var evm =
                                ModelTranslatorContextItem.GetEntityModelTranslator(Context)
                                .TranslateModelToDslModel(null, new DslModeling.Partition(docData.Store)) as EntityDesignerViewModel;
                            diagram = CreateDslDiagram(evm);
                            transaction.Commit();
                        }
                    }
                }
            }
            return(diagram);
        }
        private EntityDesignerDiagram CreateDslDiagram(EntityDesignerViewModel evm)
        {
            var docData = DocData as MicrosoftDataEntityDesignDocDataBase;
            EntityDesignerDiagram diagram = null;

            Debug.Assert(docData != null, "DocData is not a type of MicrosoftDataEntityDesignDocDataBase");
            if (docData != null)
            {
                diagram = MicrosoftDataEntityDesignSerializationHelper.Instance.CreateDiagramHelper(docData.GetDiagramPartition(), evm);
                // Set diagram name here otherwise DSL will assign one when diagram is loaded in the view which causes a transaction to be committed.
                // When the transaction is committed our custom DSL rules will get fired. At that point Debug.Assert might be fired because the xref might not properly set.
                // It doesn't matter if the name is the same across multiple diagram because we don't use it.
                diagram.Name = Path.GetFileNameWithoutExtension(DocData.FileName);
            }
            return(diagram);
        }
        public void ReversionModel_converts_model_namespaces_to_target_schema_version()
        {
            var model = CreateModel(EntityFrameworkVersion.Version3);

            var tempUri = new Uri("http://tempuri");

            var mockModelManager =
                new Mock <ModelManager>(new Mock <IEFArtifactFactory>().Object, new Mock <IEFArtifactSetFactory>().Object);

            using (var modelManager = mockModelManager.Object)
            {
                var mockModelProvider = new Mock <XmlModelProvider>();
                mockModelProvider
                .Setup(p => p.BeginTransaction(It.IsAny <string>(), It.IsAny <object>()))
                .Returns(new Mock <XmlTransaction>().Object);

                var mockFrameManager = new Mock <DocumentFrameMgr>(new Mock <IXmlDesignerPackage>().Object);
                var mockPackage      = new Mock <IEdmPackage>();
                mockPackage.Setup(p => p.DocumentFrameMgr).Returns(mockFrameManager.Object);

                var mockEditingContext = new Mock <EditingContext>();
                var mockArtifact       = new Mock <EntityDesignArtifact>(modelManager, tempUri, mockModelProvider.Object);
                mockArtifact.Setup(a => a.CanEditArtifact()).Returns(true);
                mockArtifact.Setup(a => a.XDocument).Returns(model);

#if DEBUG
                mockArtifact
                .Setup(
                    a => a.GetVerifyModelIntegrityVisitor(
                        It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <bool>()))
                .Returns(new Mock <VerifyModelIntegrityVisitor>().Object);
#endif

                Assert.False(mockArtifact.Object.IsDirty);

                EntityDesignerDiagram.ReversionModel(
                    mockPackage.Object, mockEditingContext.Object, mockArtifact.Object, EntityFrameworkVersion.Version2);

                Assert.True(mockArtifact.Object.IsDirty);
                Assert.True(XNode.DeepEquals(CreateModel(EntityFrameworkVersion.Version2), model));
                mockFrameManager.Verify(m => m.SetCurrentContext(mockEditingContext.Object), Times.Once());
            }
        }
        internal static EntityDesignerDiagram GetExistingViewDiagram(MicrosoftDataEntityDesignDocDataBase docData, string diagramId)
        {
            EntityDesignerDiagram diagram = null;
            var diagrams = docData.GetDiagramPartition().ElementDirectory.FindElements <EntityDesignerDiagram>();

            if (diagrams.Count > 0)
            {
                if (String.IsNullOrEmpty(diagramId) == false)
                {
                    diagram = diagrams.Where(d => d.DiagramId == diagramId).FirstOrDefault();
                }
                else
                {
                    // If the diagramid is not set, just select the first diagram.
                    diagram = diagrams[0];
                }
            }
            return(diagram);
        }
 internal EntityDesignerDiagramAdd(EntityDesignerDiagram diagram)
     : base(diagram)
 {
 }
Example #12
0
        internal override void SaveModelAndDiagram(
            SerializationResult serializationResult, EntityDesignerViewModel modelRoot, string modelFileName, EntityDesignerDiagram diagram,
            string diagramFileName, Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
        {
            // only save the model
            base.SaveModel(serializationResult, modelRoot, modelFileName, encoding, writeOptionalPropertiesWithDefaultValue);

            if (!serializationResult.Failed)
            {
                // flip our dirty bit (as long as we aren't trying to save the auto-recovery backup file)
                var artifact = EditingContextManager.GetArtifact(modelRoot.EditingContext);
                Debug.Assert(artifact != null, "Failed to get a valid EFArtifact from the context");

                IEntityDesignDocData docData = null;
                var fileName = String.Empty;
                if (artifact != null)
                {
                    fileName = artifact.Uri.LocalPath;
                }

                docData = VSHelpers.GetDocData(PackageManager.Package, fileName) as IEntityDesignDocData;
                Debug.Assert(docData != null, "Couldn't locate our DocData");
                if (artifact != null &&
                    docData != null &&
                    !string.Equals(docData.BackupFileName, modelFileName, StringComparison.OrdinalIgnoreCase))
                {
                    artifact.IsDirty = false;
                }

                // SaveDiagram file if the file exists
                // TODO: What happened if saving diagram file failed? Should we rollback the model file?
                var diagramDocData =
                    VSHelpers.GetDocData(PackageManager.Package, fileName + EntityDesignArtifact.ExtensionDiagram) as XmlModelDocData;
                if (diagramDocData != null)
                {
                    int saveIsCancelled;
                    diagramDocData.SaveDocData(VSSAVEFLAGS.VSSAVE_SilentSave, out diagramFileName, out saveIsCancelled);
                }
            }
        }
 protected EntityDesignerDiagramModelChange(EntityDesignerDiagram diagram)
 {
     _diagram = diagram;
 }
Example #14
0
        public void TransactionCommit(EntityDesignerDiagram diagram)
        {
            //If this is a Drag & Drop from the SE transaction, then arrange the new elements
            if (_autoArrangeInfo.Tracking)
            {
                if (_autoArrangeInfo.Objects.Count > 0 ||
                    _autoArrangeInfo.HiddenObjects.Count > 0)
                {
                    //Arrange the new elements before the transaction finishes:
                    using (var t = diagram.Store.TransactionManager.BeginTransaction(Resources.Tx_LayoutDiagram))
                    {
                        //Place single object where the user dropped, and multiple get autoarranged
                        if (_autoArrangeInfo.Objects.Count > 0)
                        {
                            //Place the first entity-type-shape to where the user released the mouse and auto layout the rest.
                            var haveDropPoint      = (!_autoArrangeDropPoint.IsEmpty);
                            var shapesToAutoLayout = new List <ShapeElement>();

                            var hasSetUserDefinedPosition = false;

                            foreach (var shape in _autoArrangeInfo.Objects)
                            {
                                var firstShape = shape as EntityTypeShape;
                                if (haveDropPoint &&
                                    firstShape != null &&
                                    !hasSetUserDefinedPosition)
                                {
                                    firstShape.Location       = _autoArrangeDropPoint;
                                    hasSetUserDefinedPosition = true;
                                }
                                else
                                {
                                    shapesToAutoLayout.Add(shape);
                                }
                            }

                            if (shapesToAutoLayout.Count > 0)
                            {
                                diagram.AutoLayoutDiagram(shapesToAutoLayout);
                            }

                            t.Commit();
                        }

                        _autoArrangeInfo.Objects.Clear();
                    }

                    //Add hidden objects to 0,0
                    if (_autoArrangeInfo.HiddenObjects.Count > 0)
                    {
                        foreach (var se in _autoArrangeInfo.HiddenObjects)
                        {
                            var cs = se as EntityTypeShape;
                            cs.Location = new PointD(0, 0);
                        }

                        _autoArrangeInfo.HiddenObjects.Clear();
                    }
                }
            }
        }
        /// <summary>
        ///     This class will set the focus on the "most-appropriate" DSL node for the given EFObject and DSL Diagram.  It is assumed that the
        ///     EFObject is either a C-Space node, or an M-space node.
        /// </summary>
        internal static bool NavigateToDSLNodeInDiagram(EntityDesignerDiagram diagram, EFObject efobject)
        {
            var foundDSLElementMatchInDiagram = false;
            var context = PackageManager.Package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(efobject.Artifact.Uri);

            // find the model parent (if this is a c-space object)
            var cModel = efobject.GetParentOfType(typeof(ConceptualEntityModel)) as ConceptualEntityModel;

            // by default, we assume that this our c-space object
            var      cspaceEFObject = efobject;
            EFObject mspaceEFObject = null;

            if (cModel == null)
            {
                var mModel = efobject.GetParentOfType(typeof(MappingModel)) as MappingModel;
                Debug.Assert(mModel != null, "efobject is neither in c-space or s-space");

                // if this is a mapping node, then we want to find the closest corresponding c-space node
                // to which this mapping node is mapped, and set the focus on that.
                cspaceEFObject = GetCSpaceEFObjectForMSpaceEFObject(efobject);
                mspaceEFObject = efobject;
            }

            // navigate to the shape in the DSL designer
            var diagramItemCollection = new DiagramItemCollection();

            RetrieveDiagramItemCollectionForEFObject(diagram, cspaceEFObject, diagramItemCollection);
            if (diagram != null &&
                diagramItemCollection.Count > 0)
            {
                diagram.Show();

                if (diagram.ActiveDiagramView != null)
                {
                    diagram.ActiveDiagramView.Focus();
                    diagram.ActiveDiagramView.Selection.Set(diagramItemCollection);
                    diagram.EnsureSelectionVisible();
                }
                else
                {
                    // If no active view exists, do the following:
                    // - Set the selection on the first associated views (if any).
                    // - Set InitialSelectionDIagramItemSelectionProperty to prevent the first EntityTypeShape to be selected (default behavior)
                    //   This case can happen when the diagram is not initialized or is not fully rendered.
                    diagram.InitialDiagramItemSelection = diagramItemCollection;
                    if (diagram.ClientViews != null &&
                        diagram.ClientViews.Count > 0)
                    {
                        foreach (DiagramClientView clientView in diagram.ClientViews)
                        {
                            clientView.Selection.Set(diagramItemCollection);
                            clientView.Selection.EnsureVisible(DiagramClientView.EnsureVisiblePreferences.ScrollIntoViewCenter);
                            break;
                        }
                    }
                }
                foundDSLElementMatchInDiagram = true;
            }

            if (mspaceEFObject != null) // navigate to the item in the mapping screen (if we are doing MSL items)
            {
                var mappingDetailsInfo = context.Items.GetValue <MappingDetailsInfo>();
                if (mappingDetailsInfo.MappingDetailsWindow != null)
                {
                    mappingDetailsInfo.MappingDetailsWindow.NavigateTo(mspaceEFObject);
                }
            }

            return(foundDSLElementMatchInDiagram);
        }
Example #16
0
        internal static void TranslateDiagram(EntityDesignerDiagram diagram, DesignerModel.Diagram modelDiagram)
        {
            var viewModel = diagram.ModelElement;

            viewModel.ModelXRef.Add(modelDiagram, diagram, viewModel.EditingContext);

            using (var t = diagram.Store.TransactionManager.BeginTransaction("Translate diagram", true))
            {
                // list of shapes that don't have corresponding element in model and require auto-layout
                var shapesToAutoLayout = new List <ViewModelDiagram.ShapeElement>();

                // try to find object in model for each shape on a diagram
                foreach (var shapeElement in diagram.NestedChildShapes)
                {
                    var entityShape = shapeElement as EntityTypeShape;
                    if (entityShape != null &&
                        entityShape.ModelElement != null)
                    {
                        var modelEntity = viewModel.ModelXRef.GetExisting(entityShape.ModelElement) as ModelEntityType;
                        if (modelEntity != null)
                        {
                            var modelEntityTypeShape =
                                modelDiagram.EntityTypeShapes.FirstOrDefault(ets => ets.EntityType.Target == modelEntity);
                            if (modelEntityTypeShape != null)
                            {
                                viewModel.ModelXRef.Add(modelEntityTypeShape, entityShape, viewModel.EditingContext);
                                var rectangle = new ViewModelDiagram.RectangleD(
                                    modelEntityTypeShape.PointX.Value, modelEntityTypeShape.PointY.Value
                                    , modelEntityTypeShape.Width.Value, 0.0);
                                entityShape.AbsoluteBounds = rectangle;
                                entityShape.IsExpanded     = modelEntityTypeShape.IsExpanded.Value;
                                entityShape.FillColor      = modelEntityTypeShape.FillColor.Value;
                            }
                        }
                        if (viewModel.ModelXRef.GetExisting(entityShape) == null)
                        {
                            shapesToAutoLayout.Add(entityShape);
                        }
                        continue;
                    }

                    var associationConnector = shapeElement as AssociationConnector;
                    if (associationConnector != null &&
                        associationConnector.ModelElement != null)
                    {
                        var modelAssociation = viewModel.ModelXRef.GetExisting(associationConnector.ModelElement) as ModelAssociation;
                        if (modelAssociation != null)
                        {
                            var modelAssociationConnector =
                                modelDiagram.AssociationConnectors.FirstOrDefault(ac => ac.Association.Target == modelAssociation);
                            if (modelAssociationConnector != null)
                            {
                                viewModel.ModelXRef.Add(modelAssociationConnector, associationConnector, viewModel.EditingContext);
                                TranslateAssociationConnectors(associationConnector, modelAssociationConnector, shapesToAutoLayout);
                            }
                        }
                        continue;
                    }

                    var inheritanceConnector = shapeElement as InheritanceConnector;
                    if (inheritanceConnector != null &&
                        inheritanceConnector.ModelElement != null)
                    {
                        var entityTypeBase = viewModel.ModelXRef.GetExisting(inheritanceConnector.ModelElement) as EntityTypeBaseType;
                        var modelEntity    = entityTypeBase.Parent as ModelEntityType;
                        if (modelEntity != null)
                        {
                            var modelInheritanceConnector =
                                modelDiagram.InheritanceConnectors.FirstOrDefault(ic => ic.EntityType.Target == modelEntity);
                            if (modelInheritanceConnector != null)
                            {
                                viewModel.ModelXRef.Add(modelInheritanceConnector, inheritanceConnector, viewModel.EditingContext);
                                TranslateInheritanceConnectors(inheritanceConnector, modelInheritanceConnector, shapesToAutoLayout);
                            }
                        }
                        continue;
                    }
                }

                diagram.AutoLayoutDiagram(shapesToAutoLayout);

                // initiate zoom level, grid and scalar property options
                diagram.ZoomLevel          = modelDiagram.ZoomLevel.Value;
                diagram.ShowGrid           = modelDiagram.ShowGrid.Value;
                diagram.SnapToGrid         = modelDiagram.SnapToGrid.Value;
                diagram.DisplayNameAndType = modelDiagram.DisplayType.Value;
                diagram.DiagramId          = modelDiagram.Id.Value;
                diagram.Title = modelDiagram.Name.Value;

                t.Commit();
            }
        }
        private static void RetrieveDiagramItemCollectionForEFObject(
            EntityDesignerDiagram diagram, EFObject efobject, DiagramItemCollection diagramItemCollection)
        {
            if (efobject == null)
            {
                return;
            }

            var cModel = efobject.RuntimeModelRoot() as ConceptualEntityModel;

            if (cModel == null)
            {
                // this either isn't a c-space object, or it is the ConceptualEntityModel node, so just return null
                return;
            }

            // if this is a child element of the association, return the diagram item for the association
            if (!(efobject is Association))
            {
                var association = efobject.GetParentOfType(typeof(Association)) as Association;
                if (association != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection);
                    return;
                }
            }

            if (efobject is Association)
            {
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject);
                if (shapeElement != null)
                {
                    diagramItemCollection.Add(new DiagramItem(shapeElement));
                    return;
                }
            }
            else if (efobject is NavigationProperty)
            {
                var np              = efobject as NavigationProperty;
                var shapeElement    = GetDesignerShapeElementForEFObject(diagram, np.Parent);
                var entityTypeShape = shapeElement as EntityTypeShape;

                if (entityTypeShape != null)
                {
                    // get the view model navigation property
                    var vmNavProp = diagram.ModelElement.ModelXRef.GetExisting(np) as ViewModel.NavigationProperty;

                    // try to create the DiagramItem from this
                    if (vmNavProp != null)
                    {
                        var index = entityTypeShape.NavigationCompartment.Items.IndexOf(vmNavProp);
                        if (index >= 0)
                        {
                            diagramItemCollection.Add(
                                new DiagramItem(
                                    entityTypeShape.NavigationCompartment, entityTypeShape.NavigationCompartment.ListField,
                                    new ListItemSubField(index)));
                            return;
                        }
                    }
                }
            }
            else if (efobject is Property)
            {
                var prop = efobject as Property;
                if (prop.IsComplexTypeProperty)
                {
                    // complex type properties are not supported in the designer
                    return;
                }
                var shapeElement    = GetDesignerShapeElementForEFObject(diagram, prop.Parent);
                var entityTypeShape = shapeElement as EntityTypeShape;
                if (entityTypeShape != null)
                {
                    // get the view model  property
                    var vmProp = diagram.ModelElement.ModelXRef.GetExisting(prop) as ViewModel.Property;

                    if (vmProp != null)
                    {
                        var index = entityTypeShape.PropertiesCompartment.Items.IndexOf(vmProp);
                        if (index >= 0)
                        {
                            diagramItemCollection.Add(
                                new DiagramItem(
                                    entityTypeShape.PropertiesCompartment, entityTypeShape.PropertiesCompartment.ListField,
                                    new ListItemSubField(index)));
                            return;
                        }
                    }
                }
            }
            else if (efobject is EntityType)
            {
                var shapeElement = GetDesignerShapeElementForEFObject(diagram, efobject);
                if (shapeElement != null)
                {
                    diagramItemCollection.Add(new DiagramItem(shapeElement));
                    return;
                }
            }
            else if (efobject is EntitySet)
            {
                var es = efobject as EntitySet;
                foreach (var entityType in es.GetEntityTypesInTheSet())
                {
                    if (entityType != null)
                    {
                        RetrieveDiagramItemCollectionForEFObject(diagram, entityType, diagramItemCollection);
                    }
                }
                return;
            }
            else if (efobject is AssociationSet)
            {
                // return a diagram item for the association
                var associationSet = efobject as AssociationSet;
                var association    = associationSet.Association.Target;
                if (association != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, association, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is AssociationSetEnd)
            {
                var associationSetEnd = efobject as AssociationSetEnd;
                var end = associationSetEnd.Role.Target;
                if (end != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, end, diagramItemCollection);
                    return;
                }
                else
                {
                    var es = associationSetEnd.EntitySet.Target;
                    if (es != null)
                    {
                        RetrieveDiagramItemCollectionForEFObject(diagram, es, diagramItemCollection);
                        return;
                    }
                }
            }
            else if (efobject is PropertyRef)
            {
                var pref = efobject as PropertyRef;
                if (pref.Name.Target != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, pref.Name.Target, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is PropertyRefContainer)
            {
                var prefContainer = efobject as PropertyRefContainer;

                // just use the first entry in the list.
                foreach (var pref in prefContainer.PropertyRefs)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, pref, diagramItemCollection);
                    return;
                }
            }
            else if (efobject is EFAttribute)
            {
                // this is an EFAttribute node, so get the DiagramItem for the parent
                RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection);
                return;
            }
            else if (efobject is ConceptualEntityModel)
            {
                // nothing in the DSL surface to map to, so return null
                return;
            }
            else if (efobject is ConceptualEntityContainer)
            {
                // nothing in the DSL surface to map to, so return null
                return;
            }
            else if (efobject is FunctionImport)
            {
                // nothing in the DSL surface to map to, so return null
                return;
            }
            else
            {
                Debug.Fail("unexpected type of efobject.  type = " + efobject.GetType());
                if (efobject.Parent != null)
                {
                    RetrieveDiagramItemCollectionForEFObject(diagram, efobject.Parent, diagramItemCollection);
                }
            }
        }