src/Misc/EFTools/EntityDesignEntityDesigner/CustomCode/Diagram/EntityDesignerDiagram.cs
/// <summary>
///     Creates a function import; if there is a selected entity type, it will use that for the return type.
/// </summary>
Creates a function import; if there is a selected entity type, it will use that for the return type.
Creates a function import ; if there is a selected entity type it will use that for the return type .
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        public void AddNewFunctionImport(EntityTypeShape entityShape)
        {
            if ((Partition.GetLocks() & Locks.Add) == Locks.Add)
            {
                return;
            }
            ViewModelEntityType baseEntity = null;
            Model.Entity.EntityType modelEntity = null;
            if (entityShape != null)
            {
                baseEntity = entityShape.TypedModelElement;
                Debug.Assert(baseEntity != null);
                modelEntity = ModelElement.ModelXRef.GetExisting(baseEntity) as Model.Entity.EntityType;
                Debug.Assert(modelEntity != null);
            }
            var cModel = ModelElement.ModelXRef.GetExisting(ModelElement) as ConceptualEntityModel;
            Debug.Assert(cModel != null, "Could not find a conceptual entity model associated with this artifact");
            ConceptualEntityContainer cContainer = null;
            if (cModel != null)
            {
                cContainer = cModel.FirstEntityContainer as ConceptualEntityContainer;
                Debug.Assert(cContainer != null, "There is no conceptual entity container in the conceptual entity model");
            }
            var artifactService = ModelElement.EditingContext.GetEFArtifactService();
            Debug.Assert(
                artifactService != null && artifactService.Artifact != null,
                "There is no artifact service/artifact associated with this editing context");
            StorageEntityModel sModel = null;
            EntityContainerMapping ecMapping = null;
            if (artifactService != null
                && artifactService.Artifact != null)
            {
                sModel = artifactService.Artifact.StorageModel();
                Debug.Assert(sModel != null, "Could not find a storage entity model associated with this artifact");
                var mModel = artifactService.Artifact.MappingModel();
                Debug.Assert(mModel != null, "Could not find a mapping model associated with this artifact");
                if (mModel != null)
                {
                    ecMapping = mModel.FirstEntityContainerMapping;
                    Debug.Assert(
                        ecMapping != null,
                        "There must be an entity container mapping in the mapping model to create the function import mapping");
                }
            }
            if (cModel != null
                && sModel != null
                && cContainer != null
                && ecMapping != null)
            {
                var schemaVersion = artifactService.Artifact.SchemaVersion;
                if (null == schemaVersion)
                {
                    Debug.Assert(
                        false,
                        typeof(EntityDesignerDiagram).Name + " could not determine Version for path "
                        + artifactService.Artifact.Uri.LocalPath);
                    return;
                }
                EntityDesignViewModelHelper.CreateFunctionImport(
                    ModelElement.EditingContext,
                    artifactService.Artifact,
                    null,
                    sModel,
                    cModel,
                    cContainer,
                    modelEntity,
                    EfiTransactionOriginator.EntityDesignerOriginatorId);
            }
        }
[ SuppressMessage ( " " , " " ) ] public void AddNewFunctionImport ( EntityTypeShape entityShape ) { if ( ( Partition . GetLocks ( ) & Locks . Add ) == Locks . Add ) { return ; } ViewModelEntityType baseEntity = null ; Model . Entity . EntityType modelEntity = null ; if ( entityShape != null ) { baseEntity = entityShape . TypedModelElement ; Debug . Assert ( baseEntity != null ) ; modelEntity = ModelElement . ModelXRef . GetExisting ( baseEntity ) as Model . Entity . EntityType ; Debug . Assert ( modelEntity != null ) ; } var cModel = ModelElement . ModelXRef . GetExisting ( ModelElement ) as ConceptualEntityModel ; Debug . Assert ( cModel != null , " " ) ; ConceptualEntityContainer cContainer = null ; if ( cModel != null ) { cContainer = cModel . FirstEntityContainer as ConceptualEntityContainer ; Debug . Assert ( cContainer != null , " " ) ; } var artifactService = ModelElement . EditingContext . GetEFArtifactService ( ) ; Debug . Assert ( artifactService != null && artifactService . Artifact != null , " " ) ; StorageEntityModel sModel = null ; EntityContainerMapping ecMapping = null ; if ( artifactService != null && artifactService . Artifact != null ) { sModel = artifactService . Artifact . StorageModel ( ) ; Debug . Assert ( sModel != null , " " ) ; var mModel = artifactService . Artifact . MappingModel ( ) ; Debug . Assert ( mModel != null , " " ) ; if ( mModel != null ) { ecMapping = mModel . FirstEntityContainerMapping ; Debug . Assert ( ecMapping != null , " " ) ; } } if ( cModel != null && sModel != null && cContainer != null && ecMapping != null ) { var schemaVersion = artifactService . Artifact . SchemaVersion ; if ( null == schemaVersion ) { Debug . Assert ( false , typeof ( EntityDesignerDiagram ) . Name + " " + artifactService . Artifact . Uri . LocalPath ) ; return ; } EntityDesignViewModelHelper . CreateFunctionImport ( ModelElement . EditingContext , artifactService . Artifact , null , sModel , cModel , cContainer , modelEntity , EfiTransactionOriginator . EntityDesignerOriginatorId ) ; } }
Creates a function import; if there is a selected entity type, it will use that for the return type.
Creates a function import ; if there is a selected entity type it will use that for the return type .
// get the necessary conceptual model elements // get the necessary storage model elements and mapping model elements
entityShape
EntityTypeShape