Beispiel #1
0
        /// <summary>
        ///     Add commands to create and set the facets for a new complex type property to match the column.
        /// </summary>
        internal static void AddCreateComplexTypePropertyCommands(
            StorageEntityModel storageModel, IRawDataSchemaColumn column, CreateComplexTypeCommand cmdNewComplexType,
            ComplexType complexType, IList <Command> commands)
        {
            // Assert if both cmdNewComplexType and complexType are null or if both are not null.
            Debug.Assert(
                ((cmdNewComplexType != null && complexType == null) || (cmdNewComplexType == null && complexType != null)),
                "Both cmdNewComplexType and complexType are null or both are not null. cmdNewComplexType is null : "
                + (cmdNewComplexType == null).ToString() + ", complexType is null : " + (complexType == null).ToString());

            if ((cmdNewComplexType != null && complexType == null) ||
                (cmdNewComplexType == null && complexType != null))
            {
                // Skip creating the complex type property for a column if the column type is unknown or not supported ( providerDataType == -1 ).
                if (column.ProviderDataType != -1)
                {
                    var primitiveType = ModelHelper.GetPrimitiveType(storageModel, column.NativeDataType, column.ProviderDataType);
                    // We only create complex type property if primitive type is known.
                    if (primitiveType != null)
                    {
                        CreateComplexTypePropertyCommand cmdNewComplexTypeProperty = null;
                        // if complex type is not created yet.
                        if (cmdNewComplexType != null)
                        {
                            cmdNewComplexTypeProperty = new CreateComplexTypePropertyCommand(
                                // Automatically "fix" the property Name if it contains bad character.
                                // We need to do this since we don't let the user to change the property name from the Function Import dialog.
                                ModelHelper.CreateValidSimpleIdentifier(column.Name),
                                cmdNewComplexType,
                                primitiveType.GetEdmPrimitiveType().Name,
                                column.IsNullable);
                            commands.Add(cmdNewComplexTypeProperty);
                        }
                        else
                        {
                            cmdNewComplexTypeProperty = new CreateComplexTypePropertyCommand(
                                // Automatically "fix" the property Name if it contains bad character.
                                // We need to do this since we don't let the user to change the property name from the Function Import dialog.
                                ModelHelper.CreateValidSimpleIdentifier(column.Name),
                                complexType,
                                primitiveType.GetEdmPrimitiveType().Name,
                                column.IsNullable);
                            commands.Add(cmdNewComplexTypeProperty);
                        }

                        // We only update the facets that are displayed in Function Import dialog return type view list:
                        // - Nullable.
                        // - Max Size.
                        // - Precision.
                        // - Scale.
                        var cmdSetPropertyFacets = new SetPropertyFacetsCommand(
                            cmdNewComplexTypeProperty
                            , null // Default value
                            , ModelHelper.GetMaxLengthFacetValue(column.Size)
                            , null // Fixed Length
                            , DefaultableValueUIntOrNone.GetFromNullableUInt(column.Precision)
                            , DefaultableValueUIntOrNone.GetFromNullableUInt(column.Scale)
                            , null // unicode
                            , null // collation
                            , null // concurrency mode
                            );
                        commands.Add(cmdSetPropertyFacets);
                    }
                }
            }
        }
        /// <summary>
        ///     Add commands to create and set the facets for a new complex type property to match the column.
        /// </summary>
        internal static void AddCreateComplexTypePropertyCommands(
            StorageEntityModel storageModel, IRawDataSchemaColumn column, CreateComplexTypeCommand cmdNewComplexType,
            ComplexType complexType, IList<Command> commands)
        {
            // Assert if both cmdNewComplexType and complexType are null or if both are not null.
            Debug.Assert(
                ((cmdNewComplexType != null && complexType == null) || (cmdNewComplexType == null && complexType != null)),
                "Both cmdNewComplexType and complexType are null or both are not null. cmdNewComplexType is null : "
                + (cmdNewComplexType == null).ToString() + ", complexType is null : " + (complexType == null).ToString());

            if ((cmdNewComplexType != null && complexType == null)
                || (cmdNewComplexType == null && complexType != null))
            {
                // Skip creating the complex type property for a column if the column type is unknown or not supported ( providerDataType == -1 ).
                if (column.ProviderDataType != -1)
                {
                    var primitiveType = ModelHelper.GetPrimitiveType(storageModel, column.NativeDataType, column.ProviderDataType);
                    // We only create complex type property if primitive type is known.
                    if (primitiveType != null)
                    {
                        CreateComplexTypePropertyCommand cmdNewComplexTypeProperty = null;
                        // if complex type is not created yet.
                        if (cmdNewComplexType != null)
                        {
                            cmdNewComplexTypeProperty = new CreateComplexTypePropertyCommand(
                                // Automatically "fix" the property Name if it contains bad character. 
                                // We need to do this since we don't let the user to change the property name from the Function Import dialog.
                                ModelHelper.CreateValidSimpleIdentifier(column.Name),
                                cmdNewComplexType,
                                primitiveType.GetEdmPrimitiveType().Name,
                                column.IsNullable);
                            commands.Add(cmdNewComplexTypeProperty);
                        }
                        else
                        {
                            cmdNewComplexTypeProperty = new CreateComplexTypePropertyCommand(
                                // Automatically "fix" the property Name if it contains bad character. 
                                // We need to do this since we don't let the user to change the property name from the Function Import dialog.
                                ModelHelper.CreateValidSimpleIdentifier(column.Name),
                                complexType,
                                primitiveType.GetEdmPrimitiveType().Name,
                                column.IsNullable);
                            commands.Add(cmdNewComplexTypeProperty);
                        }

                        // We only update the facets that are displayed in Function Import dialog return type view list:
                        // - Nullable.
                        // - Max Size.
                        // - Precision.
                        // - Scale.
                        var cmdSetPropertyFacets = new SetPropertyFacetsCommand(
                            cmdNewComplexTypeProperty
                            , null // Default value
                            , ModelHelper.GetMaxLengthFacetValue(column.Size)
                            , null // Fixed Length
                            , DefaultableValueUIntOrNone.GetFromNullableUInt(column.Precision)
                            , DefaultableValueUIntOrNone.GetFromNullableUInt(column.Scale)
                            , null // unicode
                            , null // collation
                            , null // concurrency mode 
                            );
                        commands.Add(cmdSetPropertyFacets);
                    }
                }
            }
        }