예제 #1
0
        internal NewEntityDialog(ConceptualEntityModel model)
        {
            Debug.Assert(model != null, "model should not be null");
            _model = model;

            InitializeComponent();
            // Set the default font to VS shell font.
            var vsFont = VSHelpers.GetVSFont(Services.ServiceProvider);
            if (vsFont != null)
            {
                Font = vsFont;
            }
            keyPropertyCheckBox.Checked = true;

            propertyTypeComboBox.Items.AddRange(ModelHelper.AllPrimitiveTypesSorted(_model.Artifact.SchemaVersion));
            propertyTypeComboBox.SelectedItem = ModelConstants.Int32PropertyType;

            baseTypeComboBox.Items.Add(Resources.NoneDisplayValueUsedForUX);
            baseTypeComboBox.Items.AddRange(model.EntityTypes().ToArray());
            if (baseTypeComboBox.Items.Count > 0)
            {
                baseTypeComboBox.SelectedIndex = 0;
            }

            entityNameTextBox.Text = ModelHelper.GetUniqueNameWithNumber(
                typeof(EntityType), model, Model.Resources.Model_DefaultEntityTypeName);
            propertyNameTextBox.Text = Model.Resources.Model_IdPropertyName;
        }
 // <summary>
 //     Use this constructor if you want to remove a ComplexType (for example currently selected) from the list
 // </summary>
 internal ComplexTypePickerDialog(ConceptualEntityModel cModel, ComplexType complexTypeToRemove)
     : this(cModel)
 {
     Debug.Assert(complexTypeToRemove != null, "Null ComplexType passed");
     if (complexTypeToRemove != null)
     {
         complexTypesListBox.Items.Remove(complexTypeToRemove);
     }
 }
        public void XNamespace_returns_element_namespace_if_element_not_null()
        {
            var element = new XElement("{urn:tempuri}element");
            var modelManager = new Mock<ModelManager>(null, null).Object;
            var modelProvider = new Mock<XmlModelProvider>().Object;
            var entityDesignArtifactMock = new Mock<EntityDesignArtifact>(modelManager, new Uri("urn:dummy"), modelProvider);
            entityDesignArtifactMock.Setup(a => a.SchemaVersion).Returns(EntityFrameworkVersion.Version3);

            using (var conceptualModel = new ConceptualEntityModel(entityDesignArtifactMock.Object, element))
            {
                Assert.Same(element.Name.Namespace, conceptualModel.XNamespace);
            }
        }
예제 #4
0
        public void XNamespace_returns_element_namespace_if_element_not_null()
        {
            var element                  = new XElement("{urn:tempuri}element");
            var modelManager             = new Mock <ModelManager>(null, null).Object;
            var modelProvider            = new Mock <XmlModelProvider>().Object;
            var entityDesignArtifactMock = new Mock <EntityDesignArtifact>(modelManager, new Uri("urn:dummy"), modelProvider);

            entityDesignArtifactMock.Setup(a => a.SchemaVersion).Returns(EntityFrameworkVersion.Version3);

            using (var conceptualModel = new ConceptualEntityModel(entityDesignArtifactMock.Object, element))
            {
                Assert.Same(element.Name.Namespace, conceptualModel.XNamespace);
            }
        }
        public ExplorerConceptualEntityModel(EditingContext context, ConceptualEntityModel entityModel, ExplorerEFElement parent)
            : base(context, entityModel, parent)
        {
            _typesGhostNode = new ExplorerTypes(
                Resources.ConceptualTypesGhostNodeName, context, this);
            _complexTypesGhostNode = new ExplorerComplexTypes(Resources.ComplexTypesGhostNodeName, context, this);
            _assocsGhostNode = new ExplorerAssociations(
                Resources.ConceptualAssociationsGhostNodeName, context, this);
            _funcImportsGhostNode = new ExplorerFunctionImports(
                Resources.FunctionImportsGhostNodeName, context, this);

            _enumTypesGhostNode = null;

            if (EdmFeatureManager.GetEnumTypeFeatureState(entityModel.Artifact).IsEnabled())
            {
                _enumTypesGhostNode = new ExplorerEnumTypes(
                    Resources.EnumTypesGhostNodeName, context, this);
            }
        }
예제 #6
0
        public void XNamespace_returns_root_namespace_if_element_null()
        {
            var tmpElement = new XElement("{http://schemas.microsoft.com/ado/2009/11/edm}Schema");

            var modelManager         = new Mock <ModelManager>(null, null).Object;
            var modelProvider        = new Mock <XmlModelProvider>().Object;
            var enityDesignArtifiact =
                new Mock <EntityDesignArtifact>(modelManager, new Uri("urn:dummy"), modelProvider)
            {
                CallBase = true
            }.Object;

            enityDesignArtifiact.SetXObject(
                XDocument.Parse("<Edmx xmlns=\"http://schemas.microsoft.com/ado/2009/11/edmx\" />"));

            using (var conceptualModel = new ConceptualEntityModel(enityDesignArtifiact, tmpElement))
            {
                conceptualModel.SetXObject(null);
                Assert.Equal("http://schemas.microsoft.com/ado/2009/11/edm", conceptualModel.XNamespace);

                // resetting the element is required for clean up
                conceptualModel.SetXObject(tmpElement);
            }
        }
        public void XNamespace_returns_root_namespace_if_element_null()
        {
            var tmpElement = new XElement("{http://schemas.microsoft.com/ado/2009/11/edm}Schema");

            var modelManager = new Mock<ModelManager>(null, null).Object;
            var modelProvider = new Mock<XmlModelProvider>().Object;
            var enityDesignArtifiact =
                new Mock<EntityDesignArtifact>(modelManager, new Uri("urn:dummy"), modelProvider)
                    {
                        CallBase = true
                    }.Object;

            enityDesignArtifiact.SetXObject(
                XDocument.Parse("<Edmx xmlns=\"http://schemas.microsoft.com/ado/2009/11/edmx\" />"));

            using (var conceptualModel = new ConceptualEntityModel(enityDesignArtifiact, tmpElement))
            {
                conceptualModel.SetXObject(null);
                Assert.Equal("http://schemas.microsoft.com/ado/2009/11/edm", conceptualModel.XNamespace);

                // resetting the element is required for clean up
                conceptualModel.SetXObject(tmpElement);
            }
        }
        internal ComplexTypePickerDialog(ConceptualEntityModel cModel)
        {
            InitializeComponent();

            // Set the default font to VS shell font.
            var vsFont = VSHelpers.GetVSFont(Services.ServiceProvider);
            if (vsFont != null)
            {
                Font = vsFont;
            }

            Debug.Assert(cModel != null, "Please specify ConceptualEntityModel");
            if (cModel != null)
            {
                var complexTypes = new List<ComplexType>(cModel.ComplexTypes());
                complexTypes.Sort(EFElement.EFElementDisplayNameComparison);
                complexTypesListBox.Items.AddRange(complexTypes.ToArray());
                ViewUtils.DisplayHScrollOnListBoxIfNecessary(complexTypesListBox);
            }

            complexTypesListBox.SelectedIndexChanged += complexTypesListBox_SelectedIndexChanged;
            complexTypesListBox.MouseDoubleClick += complexTypesListBox_MouseDoubleClick;
            okButton.Enabled = ComplexType != null;
        }
        protected override void OnChildDeleted(EFContainer efContainer)
        {
            if (efContainer == _designerInfoRoot)
            {
                _designerInfoRoot = null;
            }
            else if (efContainer == _mappingModel)
            {
                _mappingModel = null;
            }
            else if (efContainer == _conceptualEntityModel)
            {
                _conceptualEntityModel = null;
            }
            else if (efContainer == _storageEntityModel)
            {
                _storageEntityModel = null;
            }

            base.OnChildDeleted(efContainer);
        }
 internal EFRuntimeModelRoot CreateRuntimeModelRoot(XElement runtimeModelRoot)
 {
     if (runtimeModelRoot.Name.LocalName == BaseEntityModel.ElementName
         && CheckForCorrectNamespace(runtimeModelRoot, SchemaManager.GetCSDLNamespaceNames(), false))
     {
         if (_conceptualEntityModel != null)
         {
             _conceptualEntityModel.Dispose();
         }
         _conceptualEntityModel = new ConceptualEntityModel(this, runtimeModelRoot);
         return _conceptualEntityModel;
     }
     else if (runtimeModelRoot.Name.LocalName == BaseEntityModel.ElementName
              && CheckForCorrectNamespace(runtimeModelRoot, SchemaManager.GetSSDLNamespaceNames(), false))
     {
         if (_storageEntityModel != null)
         {
             _storageEntityModel.Dispose();
         }
         _storageEntityModel = new StorageEntityModel(this, runtimeModelRoot);
         return _storageEntityModel;
     }
     else if (runtimeModelRoot.Name.LocalName == MappingModel.ElementName
              && CheckForCorrectNamespace(runtimeModelRoot, SchemaManager.GetMSLNamespaceNames(), false))
     {
         if (_mappingModel != null)
         {
             _mappingModel.Dispose();
         }
         _mappingModel = new MappingModel(this, runtimeModelRoot);
         return _mappingModel;
     }
     else
     {
         //Debug.Fail("Unexpected runtime model root");
         return null;
     }
 }
        internal override void Parse(ICollection<XName> unprocessedElements)
        {
            State = EFElementState.ParseAttempted;

            var path = Uri.LocalPath;
            var lastdot = path.LastIndexOf('.');
            var extension = Uri.LocalPath.Substring(lastdot, path.Length - lastdot);

            if (extension.EndsWith(ExtensionMsl, StringComparison.OrdinalIgnoreCase))
            {
                _mappingModel = new MappingModel(this, XDocument.Root);
            }
            else if (extension.EndsWith(ExtensionCsdl, StringComparison.OrdinalIgnoreCase))
            {
                _conceptualEntityModel = new ConceptualEntityModel(this, XDocument.Root);
            }
            else if (extension.EndsWith(ExtensionSsdl, StringComparison.OrdinalIgnoreCase))
            {
                _storageEntityModel = new StorageEntityModel(this, XDocument.Root);
            }
            else if (GetFileExtensions().Contains(extension))
            {
                if (_designerInfoRoot != null)
                {
                    _designerInfoRoot.Dispose();
                    _designerInfoRoot = null;
                }

                if (_storageEntityModel != null)
                {
                    _storageEntityModel.Dispose();
                    _storageEntityModel = null;
                }

                if (_mappingModel != null)
                {
                    _mappingModel.Dispose();
                    _mappingModel = null;
                }

                if (_conceptualEntityModel != null)
                {
                    _conceptualEntityModel.Dispose();
                    _conceptualEntityModel = null;
                }

                // convert the xlinq tree to our model
                foreach (var elem in XObject.Document.Elements())
                {
                    ParseSingleElement(unprocessedElements, elem);
                }
            }

            if (_designerInfoRoot != null)
            {
                _designerInfoRoot.Parse(unprocessedElements);
            }

            if (_conceptualEntityModel != null)
            {
                _conceptualEntityModel.Parse(unprocessedElements);
            }

            if (_storageEntityModel != null)
            {
                _storageEntityModel.Parse(unprocessedElements);
            }

            if (_mappingModel != null)
            {
                _mappingModel.Parse(unprocessedElements);
            }

            State = EFElementState.Parsed;
        }
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    if (_designerInfoRoot != null)
                    {
                        _designerInfoRoot.Dispose();
                        _designerInfoRoot = null;
                    }

                    if (_mappingModel != null)
                    {
                        _mappingModel.Dispose();
                        _mappingModel = null;
                    }

                    if (_conceptualEntityModel != null)
                    {
                        _conceptualEntityModel.Dispose();
                        _conceptualEntityModel = null;
                    }

                    if (_storageEntityModel != null)
                    {
                        _storageEntityModel.Dispose();
                        _storageEntityModel = null;
                    }

                    if (DiagramArtifact != null)
                    {
                        ModelManager.ClearArtifact(DiagramArtifact.Uri);
                        DiagramArtifact = null;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
 internal RenameConceptualAliasCommand(ConceptualEntityModel conceptualEntityModel, string newAlias)
 {
     _conceptualEntityModel = conceptualEntityModel;
     _newAlias = newAlias;
 }
        internal static FunctionImport CreateFunctionImport(
            EditingContext editingContext,
            EFArtifact artifact,
            Function selectedSproc,
            StorageEntityModel sModel,
            ConceptualEntityModel cModel,
            ConceptualEntityContainer cContainer,
            EntityType entityType,
            string originatingId)
        {
            FunctionImport functionImportResult = null;

            Debug.Assert(editingContext != null, "editingContext should not be null");
            Debug.Assert(artifact != null, "artifact should not be null");
            Debug.Assert(!string.IsNullOrEmpty(originatingId), "originatingId should not be null or empty");

            // show dialog appropriate to framework version
            var result = ShowNewFunctionImportDialog(
                selectedSproc,
                null /* selectedSprocName Parameter */,
                sModel,
                cModel,
                cContainer,
                DialogsResource.NewFunctionImportDialog_AddFunctionImportTitle,
                entityType);

            // if user selected OK on the dialog then create the FunctionImport
            if (DialogResult.OK == result.DialogResult)
            {
                var commands = new Collection<Command>();

                CreateComplexTypeCommand createComplexTypeCommand = null;

                // Make the decision based on what is returned by the dialog.
                // If return type is a string and result schema is not null, that means the user would like create a new complex type for the function import return.
                if (result.ReturnType is string
                    && result.Schema != null)
                {
                    createComplexTypeCommand = CreateMatchingFunctionImportCommand.AddCreateComplexTypeCommands(
                        sModel, result.ReturnType as string, result.Schema.RawColumns, commands);
                }
                    // If ReturnType is a complex type and result schema is not null, the complex type needs to be updated to be in sync with schema columns.
                else if (result.ReturnType is ComplexType
                         && result.Schema != null)
                {
                    var complexType = result.ReturnType as ComplexType;
                    var propertiesDictionary = complexType.Properties().ToDictionary(p => p.LocalName.Value);
                    CreateMatchingFunctionImportCommand.AddChangeComplexTypePropertiesCommands(
                        complexType, propertiesDictionary, result.Schema.RawColumns, commands);
                }

                CreateFunctionImportCommand cmdFuncImp;
                if (createComplexTypeCommand == null)
                {
                    cmdFuncImp = new CreateFunctionImportCommand(cContainer, result.Function, result.FunctionName, result.ReturnType);
                }
                else
                {
                    // Pass in the pre-req command to create complex type to the command.
                    cmdFuncImp = new CreateFunctionImportCommand(cContainer, result.Function, result.FunctionName, createComplexTypeCommand);
                }

                commands.Add(cmdFuncImp);

                // now add a FunctionImport and a FunctionImportMapping (if appropriate)
                if (artifact.MappingModel() != null
                    && artifact.MappingModel().FirstEntityContainerMapping != null)
                {
                    var cmdFuncImpMapping = new CreateFunctionImportMappingCommand(
                        artifact.MappingModel().FirstEntityContainerMapping, result.Function, cmdFuncImp.Id);
                    cmdFuncImpMapping.AddPreReqCommand(cmdFuncImp);
                    commands.Add(cmdFuncImpMapping);

                    IDictionary<string, string> mapPropertyNameToColumnName = null;
                    if (result.Schema != null)
                    {
                        mapPropertyNameToColumnName =
                            ModelHelper.ConstructComplexTypePropertyNameToColumnNameMapping(
                                result.Schema.Columns.Select(c => c.Name).ToList());
                    }

                    // Create explicit function-import result type mapping if the return type is a complex type.
                    if (createComplexTypeCommand != null)
                    {
                        commands.Add(
                            new CreateFunctionImportTypeMappingCommand(cmdFuncImpMapping, createComplexTypeCommand)
                                {
                                    CreateDefaultScalarProperties = true,
                                    PropertyNameToColumnNameMap = mapPropertyNameToColumnName
                                });
                    }
                    else if (result.ReturnType is ComplexType)
                    {
                        commands.Add(
                            new CreateFunctionImportTypeMappingCommand(cmdFuncImpMapping, result.ReturnType as ComplexType)
                                {
                                    CreateDefaultScalarProperties = true,
                                    PropertyNameToColumnNameMap = mapPropertyNameToColumnName
                                });
                    }
                }

                var cp = new CommandProcessor(editingContext, originatingId, Resources.Tx_CreateFunctionImport, commands);
                cp.Invoke();

                functionImportResult = cmdFuncImp.FunctionImport;
                NavigateToFunction(functionImportResult);
            }

            return functionImportResult;
        }
 /// <summary>
 ///     Construct a return type to be used for the FunctionImport
 /// </summary>
 private static object ConstructReturnType(
     IRawDataSchemaProcedure schemaProcedure, ConceptualEntityModel cModel,
     StorageEntityModel sModel, string functionImportResultBaseName)
 {
     if (null == schemaProcedure)
     {
         Debug.Fail("null SchemaProcedure not allowed");
         return null;
     }
     else
     {
         var colCount = schemaProcedure.RawColumns.Count;
         if (0 == colCount)
         {
             // zero columns is equivalent to no return type
             return Resources.NoneDisplayValueUsedForUX;
         }
         else if (1 == colCount)
         {
             // if 1 columns return a collection of scalars
             var col = schemaProcedure.RawColumns[0];
             var primType = ModelHelper.GetPrimitiveType(sModel, col.NativeDataType, col.ProviderDataType);
             if (null == primType)
             {
                 Debug.Fail(
                     "Could not find primitive type for column with NativeDataType = " + col.NativeDataType + ", ProviderDataType = "
                     + col.ProviderDataType);
                 return null;
             }
             else
             {
                 return primType.GetEdmPrimitiveType();
             }
         }
         else
         {
             // if more than 1 column return a new ComplexType name (this will cause a new ComplexType with that name to be created)
             var proposedName = String.Format(CultureInfo.CurrentCulture, "{0}_Result", functionImportResultBaseName);
             var complexTypeName = ModelHelper.GetUniqueName(typeof(ComplexType), cModel, proposedName);
             return complexTypeName;
         }
     }
 }
        // Method is moved from EntityDesignViewModelHelper. 
        internal static Object GetFunctionImportReturnType(ConceptualEntityModel cModel, FunctionImport functionImport)
        {
            object value = null;
            if (functionImport.IsReturnTypeEntityType)
            {
                if (functionImport.ReturnTypeAsEntityType.Status == BindingStatus.Known)
                {
                    value = functionImport.ReturnTypeAsEntityType.Target.NormalizedNameExternal;
                }
                else
                {
                    value = ModelHelper.UnwrapCollectionAroundFunctionImportReturnType(functionImport.ReturnTypeAsEntityType.RefName, true);
                }
            }
            else if (functionImport.IsReturnTypeComplexType)
            {
                if (functionImport.ReturnTypeAsComplexType.Status == BindingStatus.Known)
                {
                    value = functionImport.ReturnTypeAsComplexType.Target.NormalizedNameExternal;
                }
                else
                {
                    value = ModelHelper.UnwrapCollectionAroundFunctionImportReturnType(functionImport.ReturnTypeAsComplexType.RefName, true);
                }
            }
            else
            {
                value = ModelHelper.UnwrapCollectionAroundFunctionImportReturnType(functionImport.ReturnTypeAsPrimitiveType.Value);
            }

            var selectedElement = ModelHelper.FindComplexTypeEntityTypeOrPrimitiveTypeForFunctionImportReturnType(cModel, value as string);
            return selectedElement;
        }
 internal RenameConceptualNamespaceCommand(ConceptualEntityModel conceptualEntityModel, string newNamespace)
 {
     _conceptualEntityModel = conceptualEntityModel;
     _newNamespace = newNamespace;
 }
        private static EntityDesignNewFunctionImportResult ShowNewFunctionImportDialog(
            Function selectedSproc,
            string selectedSprocName,
            StorageEntityModel sModel,
            ConceptualEntityModel cModel,
            ConceptualEntityContainer cContainer,
            string dialogTitle,
            Object selectedObject)
        {
            using (var dialog = new NewFunctionImportDialog(
                selectedSproc,
                selectedSprocName,
                sModel.Functions(),
                cModel.ComplexTypes(),
                cModel.EntityTypes(),
                cContainer,
                selectedObject))
            {
                dialog.Text = dialogTitle;

                var dialogResult = dialog.ShowDialog();

                var result = new EntityDesignNewFunctionImportResult
                    {
                        DialogResult = dialogResult,
                        Function = dialog.Function,
                        FunctionName = dialog.FunctionImportName,
                        IsComposable = dialog.IsComposable,
                        ReturnType = dialog.ReturnType,
                        Schema = dialog.Schema
                    };

                return result;
            }
        }
        private void RecordInheritanceAndEntityTypeMappings(ConceptualEntityModel cem)
        {
            // ensure _cEntityTypeToEntityTypeIdentity has been constructed
            Debug.Assert(null != _cEntityTypeNameToEntityTypeIdentity, "Null _cEntityTypeToEntityTypeIdentity");

            // now loop over EntityTypes. For each EntityType that has a base
            // type, map each DatabaseObject in the EntityTypeIdentity which is the
            // child type's identity to all TablesAndViews in the base type (and to 
            // all TablesAndViews in its base-type and so on up the chain).
            //
            // Note: although the normal case is a mapping 1 DatabaseObject -> 1 DatabaseObject
            // it is possible for mappings to overlap e.g. consider C-Side type C1 
            // which maps to EntityTypeIdentity {T1, T2} with a base type C2 which maps to
            // EntityTypeIdentity {T3, T4) and C-side type C3 which maps to
            // EntityTypeIdentity {T2, T5} with base type C4 which maps to {T4, T6}
            // Then this map will contain mappings:
            //   T1 -> {T3, T4}
            //   T2 -> {T3, T4, T6}
            //   T5 -> {T4, T6}
            // In the above {T3, T4, T6} is not the identity of any given C-side
            // entity type. But it allows us to know that something which maps to 
            // T2 (amongst others), has a base type which maps to T6 (amongst others).
            //
            // Also record the DatabaseObject->EntityType mappings.
            foreach (var et in cem.EntityTypes())
            {
                // Note: etEntityTypeId below will be null for unmapped EntityTypes
                var etEntityTypeId = GetEntityTypeIdentityForEntityType(et);
                if (null != etEntityTypeId)
                {
                    // record DatabaseObject->EntityType mappings
                    foreach (var etTableOrView in etEntityTypeId.TablesAndViews)
                    {
                        AddDbObjToEntityTypeNameMap(etTableOrView, et);
                    }

                    // record inheritance mappings
                    foreach (var etTableOrView in etEntityTypeId.TablesAndViews)
                    {
                        AddDbObjToEntityTypeNameMap(etTableOrView, et);

                        // loop over all ancestor types (i.e. this EntityType's base-type
                        // and its base-type etc.)
                        var baseType = et as ConceptualEntityType;
                        Debug.Assert(baseType != null, "EntityType is not a ConceptualEntityType");

                        while ((baseType = baseType.BaseType.Target) != null)
                        {
                            var baseTypeEntityTypeId = GetEntityTypeIdentityForEntityType(baseType);
                            if (null != etEntityTypeId
                                && null != baseTypeEntityTypeId)
                            {
                                foreach (var baseTypeTableOrView in baseTypeEntityTypeId.TablesAndViews)
                                {
                                    AddTableOrViewToBaseTypeMappings(etTableOrView, baseTypeTableOrView);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #20
0
 internal EnumType(ConceptualEntityModel model, XElement element)
     : base(model, element)
 {
 }
예제 #21
0
 internal ComplexType(ConceptualEntityModel model, XElement element)
     : base(model, element)
 {
 }
        internal static void EditFunctionImport(
            EditingContext editingContext,
            FunctionImport functionImport,
            StorageEntityModel sModel,
            ConceptualEntityModel cModel,
            ConceptualEntityContainer cContainer,
            object selectedObject,
            string originatingId)
        {
            Debug.Assert(editingContext != null, "editingContext should not be null");
            Debug.Assert(!string.IsNullOrEmpty(originatingId), "originatingId should not be null or empty");

            // show dialog appropriate to framework version
            var result = ShowNewFunctionImportDialog(
                functionImport.Function,
                functionImport.LocalName.Value,
                sModel,
                cModel,
                cContainer,
                DialogsResource.NewFunctionImportDialog_EditFunctionImportTitle,
                selectedObject);

            // if user selected OK on the dialog then create the FunctionImport
            if (DialogResult.OK == result.DialogResult)
            {
                var commands = new List<Command>();
                var cp = new CommandProcessor(editingContext, originatingId, Resources.Tx_UpdateFunctionImport);
                CreateComplexTypeCommand createComplexTypeCommand = null;

                // Make the decision based on what is returned by the dialog.
                // If return type is a string and result schema is not null, that means the user would like to create a new complex type for the function import return.
                if (result.ReturnType is string
                    && result.Schema != null)
                {
                    createComplexTypeCommand = CreateMatchingFunctionImportCommand.AddCreateComplexTypeCommands(
                        sModel, result.ReturnType as string, result.Schema.RawColumns, commands);
                }
                    // If ReturnType is a complex type and result schema is not null, the complex type needs to be updated to be in sync with schema columns.
                else if (result.ReturnType is ComplexType
                         && result.Schema != null)
                {
                    var complexType = result.ReturnType as ComplexType;
                    // Create Column properties dictionary. The keys will be either property's type-mapping column name if availabe or property's name.
                    var propertiesDictionary =
                        complexType.Properties().ToDictionary(p => EdmUtils.GetFunctionImportResultColumnName(functionImport, p));
                    CreateMatchingFunctionImportCommand.AddChangeComplexTypePropertiesCommands(
                        complexType, propertiesDictionary, result.Schema.RawColumns, commands);
                }

                // construct Dictionary mapping property name to column name for FunctionImportMapping
                IDictionary<string, string> mapPropertyNameToColumnName = null;
                if (result.Schema != null)
                {
                    mapPropertyNameToColumnName =
                        ModelHelper.ConstructComplexTypePropertyNameToColumnNameMapping(result.Schema.Columns.Select(c => c.Name).ToList());
                }

                // change the FunctionImport and FunctionImportMapping to match
                ChangeFunctionImportCommand cmdFuncImpSproc = null;
                // if result.IsComposable is true then set to True, but if false then use None if existing value is None, otherwise False
                var resultIsComposable = (result.IsComposable
                                              ? BoolOrNone.TrueValue
                                              : (BoolOrNone.NoneValue == functionImport.IsComposable.Value
                                                     ? BoolOrNone.NoneValue
                                                     : BoolOrNone.FalseValue));
                if (createComplexTypeCommand == null)
                {
                    cmdFuncImpSproc = new ChangeFunctionImportCommand(
                        cContainer, functionImport, result.Function, result.FunctionName, resultIsComposable, true, result.ReturnType);
                    // Create explicit function-import result type mapping if the return type is a complex type.
                    if (result.ReturnType is ComplexType)
                    {
                        cmdFuncImpSproc.PostInvokeEvent += (o, eventArgs) =>
                            {
                                if (functionImport != null
                                    && functionImport.FunctionImportMapping != null)
                                {
                                    // CreateFunctionImportTypeMappingCommand will be no op function-import's return is unchanged.
                                    CommandProcessor.InvokeSingleCommand(
                                        cp.CommandProcessorContext
                                        ,
                                        new CreateFunctionImportTypeMappingCommand(
                                            functionImport.FunctionImportMapping, result.ReturnType as ComplexType)
                                            {
                                                CreateDefaultScalarProperties = true,
                                                PropertyNameToColumnNameMap = mapPropertyNameToColumnName
                                            });
                                }
                            };
                    }
                }
                else
                {
                    // Pass in the pre-req command to create complex type to the command.
                    cmdFuncImpSproc = new ChangeFunctionImportCommand(
                        cContainer, functionImport, result.Function, result.FunctionName,
                        resultIsComposable, createComplexTypeCommand);
                    // Create explicit function-import result type mapping if the return type is a complex type.
                    cmdFuncImpSproc.PostInvokeEvent += (o, eventArgs) =>
                        {
                            if (functionImport != null
                                && functionImport.FunctionImportMapping != null)
                            {
                                CommandProcessor.InvokeSingleCommand(
                                    cp.CommandProcessorContext,
                                    new CreateFunctionImportTypeMappingCommand(
                                        functionImport.FunctionImportMapping, createComplexTypeCommand)
                                        {
                                            CreateDefaultScalarProperties = true,
                                            PropertyNameToColumnNameMap = mapPropertyNameToColumnName
                                        });
                            }
                        };
                }
                commands.Add(cmdFuncImpSproc);
                commands.ForEach(x => cp.EnqueueCommand(x));
                cp.Invoke();
            }
        }