src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/SerializationHelper/MicrosoftDataEntityDesignSerializationHelper.cs
/// <summary>
///     This method will remove all child shapes of the EntityDesignerDiagram.
/// </summary>
This method will remove all child shapes of the EntityDesignerDiagram.
This method will remove all child shapes of the EntityDesignerDiagram .
internal static void ClearDiagram(EntityDesignerViewModel viewModel)
        {
            var diagram = viewModel.GetDiagram();
            if (diagram != null)
            {
                using (var t = viewModel.Store.TransactionManager.BeginTransaction("ClearDiagram", true))
                {
                    Debug.Assert(viewModel.Partition != null, "ViewModel's Partition should never be null.");
                    if (viewModel.Partition != null)
                    {
                        var elementDirectory = viewModel.Partition.ElementDirectory;
                        Debug.Assert(
                            elementDirectory != null, "ElementDirectory in partition for view model :" + diagram.Title + " is null.");
                        if (elementDirectory != null)
                        {
                            var allElements = new List<ModelElement>(elementDirectory.AllElements.Count);
                            allElements.AddRange(elementDirectory.AllElements);
                            foreach (var melem in allElements)
                            {
                                if (melem is PresentationElement
                                    && (melem is EntityDesignerDiagram) == false)
                                {
                                    melem.Delete();
                                }
                            }
                        }
                    }
                    if (t.IsActive)
                    {
                        t.Commit();
                    }
                }
            }
        }
internal static void ClearDiagram ( EntityDesignerViewModel viewModel ) { var diagram = viewModel . GetDiagram ( ) ; if ( diagram != null ) { using ( var t = viewModel . Store . TransactionManager . BeginTransaction ( " " , true ) ) { Debug . Assert ( viewModel . Partition != null , " " ) ; if ( viewModel . Partition != null ) { var elementDirectory = viewModel . Partition . ElementDirectory ; Debug . Assert ( elementDirectory != null , " " + diagram . Title + " " ) ; if ( elementDirectory != null ) { var allElements = new List < ModelElement > ( elementDirectory . AllElements . Count ) ; allElements . AddRange ( elementDirectory . AllElements ) ; foreach ( var melem in allElements ) { if ( melem is PresentationElement && ( melem is EntityDesignerDiagram ) == false ) { melem . Delete ( ) ; } } } } if ( t . IsActive ) { t . Commit ( ) ; } } } }
This method will remove all child shapes of the EntityDesignerDiagram.
This method will remove all child shapes of the EntityDesignerDiagram .
// make copy of AllElements so that we don't modify the collection while we are iterating over it. // We are only interested to the model elements that belong to the viewModel; so look at the Partition's ElementDirectory // instead of Store's ElementDirectory which is shared across diagram. // don't delete our diagram, but remove every other presentation element
viewModel
EntityDesignerViewModel