src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/SerializationHelper/MicrosoftDataEntityDesignSerializationHelper.cs
/// <summary>
///     This method loads the DSL view model with the items in the artifact's C-Model.
/// </summary>
This method loads the DSL view model with the items in the artifact's C-Model.
This method loads the DSL view model with the items in the artifact ' s C - Model .
internal void ReloadModel(EntityDesignerViewModel viewModel)
        {
            var diagram = viewModel.GetDiagram();
            if (diagram == null)
            {
                return;
            }
            var artifact = EditingContextManager.GetArtifact(viewModel.EditingContext) as EntityDesignArtifact;
            Debug.Assert(artifact != null);
            var serializationResult = new SerializationResult();
            var serializationContext = new SerializationContext(GetDirectory(viewModel.Store), artifact.Uri.LocalPath, serializationResult);
            var transactionContext = new TransactionContext();
            transactionContext.Add(SerializationContext.TransactionContextKey, serializationContext);
            var workaroundFixSerializationTransactionValue = false;
            if (viewModel.Store.PropertyBag.ContainsKey("WorkaroundFixSerializationTransaction"))
            {
                workaroundFixSerializationTransactionValue = (bool)viewModel.Store.PropertyBag["WorkaroundFixSerializationTransaction"];
            }
            try
            {
                viewModel.Store.PropertyBag["WorkaroundFixSerializationTransaction"] = true;
                using (var t = viewModel.Store.TransactionManager.BeginTransaction("ReloadModel", true, transactionContext))
                {
                    if (artifact.ConceptualModel() == null)
                    {
                        return;
                    }
                    DesignerModel.Diagram diagramModel = null;
                    if (!string.IsNullOrEmpty(diagram.DiagramId))
                    {
                        diagramModel = artifact.DesignerInfo.Diagrams.GetDiagram(diagram.DiagramId);
                    }
                    if (diagramModel == null)
                    {
                        diagramModel = artifact.DesignerInfo.Diagrams.FirstDiagram;
                    }
                    if (diagramModel != null)
                    {
                        Debug.Assert(viewModel.ModelXRef != null, "Why ModelXRef is null?");
                        if (viewModel.ModelXRef != null)
                        {
                            viewModel.ModelXRef.Add(artifact.ConceptualModel(), viewModel, viewModel.EditingContext);
                            viewModel.ModelXRef.Add(diagramModel, diagram, viewModel.EditingContext);
                            ModelTranslatorContextItem.GetEntityModelTranslator(viewModel.EditingContext)
                                .TranslateModelToDslModel(diagramModel, viewModel.Partition);
                        }
                    }
                    if (t.IsActive)
                    {
                        t.Commit();
                    }
                }
            }
            finally
            {
                viewModel.Store.PropertyBag["WorkaroundFixSerializationTransaction"] = workaroundFixSerializationTransactionValue;
            }
        }
internal void ReloadModel ( EntityDesignerViewModel viewModel ) { var diagram = viewModel . GetDiagram ( ) ; if ( diagram == null ) { return ; } var artifact = EditingContextManager . GetArtifact ( viewModel . EditingContext ) as EntityDesignArtifact ; Debug . Assert ( artifact != null ) ; var serializationResult = new SerializationResult ( ) ; var serializationContext = new SerializationContext ( GetDirectory ( viewModel . Store ) , artifact . Uri . LocalPath , serializationResult ) ; var transactionContext = new TransactionContext ( ) ; transactionContext . Add ( SerializationContext . TransactionContextKey , serializationContext ) ; var workaroundFixSerializationTransactionValue = false ; if ( viewModel . Store . PropertyBag . ContainsKey ( " " ) ) { workaroundFixSerializationTransactionValue = ( bool ) viewModel . Store . PropertyBag [ " " ] ; } try { viewModel . Store . PropertyBag [ " " ] = true ; using ( var t = viewModel . Store . TransactionManager . BeginTransaction ( " " , true , transactionContext ) ) { if ( artifact . ConceptualModel ( ) == null ) { return ; } DesignerModel . Diagram diagramModel = null ; if ( ! string . IsNullOrEmpty ( diagram . DiagramId ) ) { diagramModel = artifact . DesignerInfo . Diagrams . GetDiagram ( diagram . DiagramId ) ; } if ( diagramModel == null ) { diagramModel = artifact . DesignerInfo . Diagrams . FirstDiagram ; } if ( diagramModel != null ) { Debug . Assert ( viewModel . ModelXRef != null , " " ) ; if ( viewModel . ModelXRef != null ) { viewModel . ModelXRef . Add ( artifact . ConceptualModel ( ) , viewModel , viewModel . EditingContext ) ; viewModel . ModelXRef . Add ( diagramModel , diagram , viewModel . EditingContext ) ; ModelTranslatorContextItem . GetEntityModelTranslator ( viewModel . EditingContext ) . TranslateModelToDslModel ( diagramModel , viewModel . Partition ) ; } } if ( t . IsActive ) { t . Commit ( ) ; } } } finally { viewModel . Store . PropertyBag [ " " ] = workaroundFixSerializationTransactionValue ; } }
This method loads the DSL view model with the items in the artifact's C-Model.
This method loads the DSL view model with the items in the artifact ' s C - Model .
// empty DSL diagram // get our artifact // To fix performance issue during reload, we turn-off layout during "serialization". // If DiagramId is not string empty, try to get the diagram from the artifact.  // There is a situation where we could not find the diagram given an ID (for example: EDMX Model's Diagram that is created by VS before SQL 11;  // In that case, we assign temporary ID to the diagram and a new ID will be generated every time the model is reloaded.) // We could safely choose the first diagram since multiple diagrams feature didn't exist in VS prior to SQL11 release. // Re-establish the xref between Escher conceptual model and DSL root model. // and between Escher Diagram model and DSL diagram model.
viewModel
EntityDesignerViewModel