src/Misc/EFTools/EntityDesignModel/Commands/CreateMatchingFunctionImportCommand.cs
/// <summary>
///     This method will queue commands to sync complex type properties and the schema columns.
///     Add the commands which change the complex type properties.
///     - Iterate complex type properties list.
///     - If no column with the same name found, add DeletePropertyCommands.
///     - If match is found, update the properties types and facets by queueing ChangePropertyTypeCommand and SetPropertyFacetsCommand
///     - Iterate schema column properties list and add the column that have not been added.
/// </summary>
/// <param name="complexType">The complex type that will be updated.</param>
/// <param name="complexTypePropertiesMap">The complex type properties map.</param>
/// <param name="columns">The DataSchema columns that are used as the source for the update.</param>
/// <param name="commands">The list of commands to which these commands will be added</param>
This method will queue commands to sync complex type properties and the schema columns.
Add the commands which change the complex type properties.
Iterate complex type properties list.
If no column with the same name found, add DeletePropertyCommands.
If match is found, update the properties types and facets by queueing ChangePropertyTypeCommand and SetPropertyFacetsCommand
Iterate schema column properties list and add the column that have not been added.
This method will queue commands to sync complex type properties and the schema columns . Add the commands which change the complex type properties . Iterate complex type properties list . If no column with the same name found add DeletePropertyCommands . If match is found update the properties types and facets by queueing ChangePropertyTypeCommand and SetPropertyFacetsCommand Iterate schema column properties list and add the column that have not been added .
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        internal static void AddChangeComplexTypePropertiesCommands(
            ComplexType complexType, IDictionary<string, Property> complexTypePropertiesMap, IList<IRawDataSchemaColumn> columns,
            IList<Command> commands)
        {
            Debug.Assert(complexTypePropertiesMap != null, "Parameter complexTypePropertiesMap is null");
            if (complexTypePropertiesMap != null)
            {
                var columnsDictionary = columns.ToDictionary(c => c.Name);
                var createdProperties = new HashSet<string>();
                var storageModel = complexType.Artifact.StorageModel();
                foreach (var propertyName in complexTypePropertiesMap.Keys)
                {
                    if (!columnsDictionary.ContainsKey(propertyName))
                    {
                        commands.Add(complexTypePropertiesMap[propertyName].GetDeleteCommand());
                    }
                    else
                    {
                        var complexTypeProperty = complexTypePropertiesMap[propertyName];
                        var schemaColumn = columnsDictionary[propertyName];
                        if (complexTypeProperty is ComplexConceptualProperty)
                        {
                            commands.Add(complexTypeProperty.GetDeleteCommand());
                            AddCreateComplexTypePropertyCommands(storageModel, schemaColumn, null, complexType, commands);
                            createdProperties.Add(propertyName);
                        }
                        else if (schemaColumn.ProviderDataType != -1)
                        {
                            var primitiveType = ModelHelper.GetPrimitiveType(
                                storageModel, schemaColumn.NativeDataType, schemaColumn.ProviderDataType);
                            if (primitiveType != null)
                            {
                                commands.Add(new ChangePropertyTypeCommand(complexTypeProperty, primitiveType.GetEdmPrimitiveType().Name));
                                commands.Add(new ChangePropertyTypeNullableCommand(complexTypeProperty, schemaColumn.IsNullable));
                                commands.Add(
                                    new SetPropertyFacetsCommand(
                                        complexTypeProperty
                                        , null 
                                        , ModelHelper.GetMaxLengthFacetValue(schemaColumn.Size) 
                                        , null 
                                        , DefaultableValueUIntOrNone.GetFromNullableUInt(schemaColumn.Precision)
                                        , DefaultableValueUIntOrNone.GetFromNullableUInt(schemaColumn.Scale)
                                        , null 
                                        , null 
                                        , null 
                                        ));
                            }
                        }
                    }
                }
                foreach (var columnName in columnsDictionary.Keys)
                {
                    if (false == complexTypePropertiesMap.ContainsKey(columnName)
                        && false == createdProperties.Contains(columnName))
                    {
                        AddCreateComplexTypePropertyCommands(storageModel, columnsDictionary[columnName], null, complexType, commands);
                    }
                }
            }
        }
[ SuppressMessage ( " " , " " ) ] internal static void AddChangeComplexTypePropertiesCommands ( ComplexType complexType , IDictionary < string , Property > complexTypePropertiesMap , IList < IRawDataSchemaColumn > columns , IList < Command > commands ) { Debug . Assert ( complexTypePropertiesMap != null , " " ) ; if ( complexTypePropertiesMap != null ) { var columnsDictionary = columns . ToDictionary ( c => c . Name ) ; var createdProperties = new HashSet < string > ( ) ; var storageModel = complexType . Artifact . StorageModel ( ) ; foreach ( var propertyName in complexTypePropertiesMap . Keys ) { if ( ! columnsDictionary . ContainsKey ( propertyName ) ) { commands . Add ( complexTypePropertiesMap [ propertyName ] . GetDeleteCommand ( ) ) ; } else { var complexTypeProperty = complexTypePropertiesMap [ propertyName ] ; var schemaColumn = columnsDictionary [ propertyName ] ; if ( complexTypeProperty is ComplexConceptualProperty ) { commands . Add ( complexTypeProperty . GetDeleteCommand ( ) ) ; AddCreateComplexTypePropertyCommands ( storageModel , schemaColumn , null , complexType , commands ) ; createdProperties . Add ( propertyName ) ; } else if ( schemaColumn . ProviderDataType != - 1 ) { var primitiveType = ModelHelper . GetPrimitiveType ( storageModel , schemaColumn . NativeDataType , schemaColumn . ProviderDataType ) ; if ( primitiveType != null ) { commands . Add ( new ChangePropertyTypeCommand ( complexTypeProperty , primitiveType . GetEdmPrimitiveType ( ) . Name ) ) ; commands . Add ( new ChangePropertyTypeNullableCommand ( complexTypeProperty , schemaColumn . IsNullable ) ) ; commands . Add ( new SetPropertyFacetsCommand ( complexTypeProperty , null , ModelHelper . GetMaxLengthFacetValue ( schemaColumn . Size ) , null , DefaultableValueUIntOrNone . GetFromNullableUInt ( schemaColumn . Precision ) , DefaultableValueUIntOrNone . GetFromNullableUInt ( schemaColumn . Scale ) , null , null , null ) ) ; } } } } foreach ( var columnName in columnsDictionary . Keys ) { if ( false == complexTypePropertiesMap . ContainsKey ( columnName ) && false == createdProperties . Contains ( columnName ) ) { AddCreateComplexTypePropertyCommands ( storageModel , columnsDictionary [ columnName ] , null , complexType , commands ) ; } } } }
This method will queue commands to sync complex type properties and the schema columns.
This method will queue commands to sync complex type properties and the schema columns .
// Iterate current properties decide whether to delete, create, update or skip. // If the column is not found in columns dictionary delete it. // Match is found between schema column and complex type property. // Special case if the property is a complex property, we just need to delete it. // Delete the complex property  // Create a new complex property // Add the property to the "created-list" so we don't create the property in the second pass. // If ProviderDataType == -1 (Unsupported type) we should skip the sync operation // Update the ComplexType's property to look like the schemaColumn // PrimitiveType is null if there is no compatible EF type for the schema column type. // sync the property type // sync the property facets. // We only update the facets that are displayed in Function Import dialog return type view list: // - Nullable. // - Max Size. // - Precision. // - Scale. // Default value // Size or MaxLength // Fixed Length // unicode // collation // concurrency mode  // Second pass: Iterate columns list to add columns that are not in complex type properties
complexType
ComplexType
The complex type that will be updated.
The complex type that will be updated .
complexTypePropertiesMap
IDictionary<string, Property>
The complex type properties map.
The complex type properties map .
columns
IList<IRawDataSchemaColumn>
The DataSchema columns that are used as the source for the update.
The DataSchema columns that are used as the source for the update .
commands
IList<Command>
The list of commands to which these commands will be added
The list of commands to which these commands will be added