/// <summary> /// Creates a new property in the passed in storage entity and optionally sets additional /// facets on the property. /// NOTE: If the cpc already has an active transaction, these changes will be in that transaction /// and the caller of this helper method must commit it to see these changes commited. /// </summary> /// <param name="cpc"></param> /// <param name="name">The name of the property</param> /// <param name="entityType">Must be a storage entity</param> /// <param name="type">The type to use for this property (cannot be empty)</param> /// <param name="nullable">Flag whether the property is nullable or not</param> /// <param name="theDefault">Optional: the default value for this property</param> /// <param name="maxLength">Optional facet</param> /// <param name="fixedLength">Optional facet</param> /// <param name="precision">Optional facet</param> /// <param name="scale">Optional facet</param> /// <param name="unicode">Optional facet</param> /// <param name="collation">Optional facet</param> /// <param name="concurrencyMode">Optional: the concurrency mode for this property</param> /// <returns>The new Property</returns> internal static Property CreateStorageProperty( CommandProcessorContext cpc, string name, StorageEntityType entityType, string type, bool?nullable, StringOrNone theDefault, StringOrPrimitive <UInt32> maxLength, BoolOrNone fixedLength, StringOrPrimitive <UInt32> precision, StringOrPrimitive <UInt32> scale, BoolOrNone unicode, StringOrNone collation, string concurrencyMode) { CommandValidation.ValidateStorageEntityType(entityType); var cpcd = new CreatePropertyCommand(name, entityType, type, nullable); var ssp = new SetPropertyFacetsCommand( cpcd, theDefault, maxLength, fixedLength, precision, scale, unicode, collation, concurrencyMode); var cp = new CommandProcessor(cpc, cpcd, ssp); cp.Invoke(); return(cpcd.CreatedProperty); }
/// <summary> /// Creates a new property in the passed in storage entity and optionally sets additional /// facets on the property. /// NOTE: If the cpc already has an active transaction, these changes will be in that transaction /// and the caller of this helper method must commit it to see these changes commited. /// </summary> /// <param name="cpc"></param> /// <param name="name">The name of the property</param> /// <param name="entityType">Must be a storage entity</param> /// <param name="type">The type to use for this property (cannot be empty)</param> /// <param name="nullable">Flag whether the property is nullable or not</param> /// <param name="theDefault">Optional: the default value for this property</param> /// <param name="maxLength">Optional facet</param> /// <param name="fixedLength">Optional facet</param> /// <param name="precision">Optional facet</param> /// <param name="scale">Optional facet</param> /// <param name="unicode">Optional facet</param> /// <param name="collation">Optional facet</param> /// <param name="concurrencyMode">Optional: the concurrency mode for this property</param> /// <returns>The new Property</returns> internal static Property CreateStorageProperty( CommandProcessorContext cpc, string name, StorageEntityType entityType, string type, bool? nullable, StringOrNone theDefault, StringOrPrimitive<UInt32> maxLength, BoolOrNone fixedLength, StringOrPrimitive<UInt32> precision, StringOrPrimitive<UInt32> scale, BoolOrNone unicode, StringOrNone collation, string concurrencyMode) { CommandValidation.ValidateStorageEntityType(entityType); var cpcd = new CreatePropertyCommand(name, entityType, type, nullable); var ssp = new SetPropertyFacetsCommand( cpcd, theDefault, maxLength, fixedLength, precision, scale, unicode, collation, concurrencyMode); var cp = new CommandProcessor(cpc, cpcd, ssp); cp.Invoke(); return cpcd.CreatedProperty; }
/// <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); } } } }