/// <summary> /// Add a list of commands to create a ComplexType matching the list of columns passed in. /// Return the initial CreateComplexTypeCommand. /// </summary> /// <param name="sModel"></param> /// <param name="complexTypeName"></param> /// <param name="columns"></param> /// <param name="commands"></param> internal static CreateComplexTypeCommand AddCreateComplexTypeCommands( StorageEntityModel sModel, string complexTypeName, IList <IRawDataSchemaColumn> columns, IList <Command> commands) { Debug.Assert(false == String.IsNullOrEmpty(complexTypeName), "The passed in complexTypeName is null or empty"); Debug.Assert(null != columns, "The passed in schema columns are null"); Debug.Assert(null != commands, "We require a pre-created list of commands to add to"); CreateComplexTypeCommand cmdNewComplexType = null; if (!string.IsNullOrEmpty(complexTypeName) && null != columns && null != commands) { cmdNewComplexType = new CreateComplexTypeCommand(complexTypeName, true); commands.Add(cmdNewComplexType); // now add commands to add appropriate properties to the ComplexType foreach (var column in columns) { // adds commands to create and set the facets for a new complex type property to match the column AddCreateComplexTypePropertyCommands(sModel, column, cmdNewComplexType, null, commands); } } return(cmdNewComplexType); }
/// <summary> /// Creates new ComplexTypeMapping inside specified FunctionImportMapping /// </summary> /// <param name="functionImportMapping"></param> /// <param name="complexType"></param> internal CreateFunctionImportTypeMappingCommand( CreateFunctionImportMappingCommand createFunctionImportMappingCmd, CreateComplexTypeCommand createComplexTypeCmd) : base(PrereqId) { AddPreReqCommand(createFunctionImportMappingCmd); AddPreReqCommand(createComplexTypeCmd); }
/// <summary> /// Creates new ComplexTypeMapping inside specified FunctionImportMapping /// </summary> /// <param name="createFunctionImportMapping"></param> /// <param name="complexType"></param> internal CreateFunctionImportTypeMappingCommand( FunctionImportMapping functionImportMapping, CreateComplexTypeCommand createComplexTypeCmd) : base(PrereqId) { CommandValidation.ValidateFunctionImportMapping(functionImportMapping); _functionImportMapping = functionImportMapping; AddPreReqCommand(createComplexTypeCmd); }
protected override void InvokeInternal(CommandProcessorContext cpc) { // first create new ComplexType _createdComplexType = CreateComplexTypeCommand.CreateComplexTypeWithDefaultName(cpc); // add a copy of Entity properties to the ComplexType var copyCmd = new CopyPropertiesCommand(new PropertiesClipboardFormat(_properties), _createdComplexType); var propertyName = ModelHelper.GetUniqueConceptualPropertyName( ComplexConceptualProperty.DefaultComplexPropertyName, _entityType); // add a new Property of created ComplexType to the Entity var createCPCmd = new CreateComplexPropertyCommand(propertyName, _entityType, _createdComplexType); var cp = new CommandProcessor(cpc, copyCmd, createCPCmd); cp.Invoke(); _createdComplexProperty = createCPCmd.Property; // preserve mappings foreach (var property in _properties) { if (property is ComplexConceptualProperty) { var createdComplexTypeProperty = _createdComplexType.FindPropertyByLocalName(property.LocalName.Value) as ComplexConceptualProperty; Debug.Assert(createdComplexTypeProperty != null, "Copied complex property not found"); if (createdComplexTypeProperty != null) { foreach (var complexPropertyMapping in property.GetAntiDependenciesOfType <ComplexProperty>()) { PreserveComplexPropertyMapping(cpc, complexPropertyMapping, createdComplexTypeProperty); } foreach (var fcp in property.GetAntiDependenciesOfType <FunctionComplexProperty>()) { PreserveFunctionComplexPropertyMapping(cpc, fcp, createdComplexTypeProperty); } } } else { var createdComplexTypeProperty = _createdComplexType.FindPropertyByLocalName(property.LocalName.Value); Debug.Assert(createdComplexTypeProperty != null, "Copied property not found"); if (createdComplexTypeProperty != null) { // update EntityTypeMappings foreach (var scalarPropertyMapping in property.GetAntiDependenciesOfType <ScalarProperty>()) { PreserveScalarPropertyMapping(cpc, scalarPropertyMapping, createdComplexTypeProperty); } // update ModificationFunctionMappings foreach (var fsp in property.GetAntiDependenciesOfType <FunctionScalarProperty>()) { PreserveFunctionScalarPropertyMapping(cpc, fsp, createdComplexTypeProperty); } } } } }
protected override void InvokeInternal(CommandProcessorContext cpc) { // create copy of the ComplexType var cmd = new CreateComplexTypeCommand(_clipboardComplexType.Name, true); CommandProcessor.InvokeSingleCommand(cpc, cmd); _createdComplexType = cmd.ComplexType; // copy child properties var cmd2 = new CopyPropertiesCommand(_clipboardComplexType.Properties, _createdComplexType); CommandProcessor.InvokeSingleCommand(cpc, cmd2); AddAnnotations(_clipboardComplexType, _createdComplexType); }
/// <summary> /// Create a Function Import whose return type being created in passed in CreateComplexTypeCommand. /// </summary> /// <param name="ec"></param> /// <param name="function"></param> /// <param name="functionImportName"></param> /// <param name="prereqCommand"></param> internal CreateFunctionImportCommand( ConceptualEntityContainer ec, Function function, string functionImportName, CreateComplexTypeCommand prereqCommand) { ValidatePrereqCommand(prereqCommand); CommandValidation.ValidateConceptualEntityContainer(ec); CommandValidation.ValidateFunction(function); Container = ec; Function = function; FunctionImportName = functionImportName; AddPreReqCommand(prereqCommand); }
/// <summary> /// Creates a complex property in the complex type being created by the passed in command /// </summary> /// <param name="name">The name of the new property</param> /// <param name="prereqCommand">Instance of CreateComplexTypeCommand; must be non null</param> /// <param name="type">The type of the property</param> /// <param name="nullable">Flag whether the property is nullable or not</param> internal CreateComplexTypePropertyCommand(string name, CreateComplexTypeCommand prereqCommand, string type, bool?nullable) : base(PrereqId) { ValidatePrereqCommand(prereqCommand); ValidateString(name); ValidateString(type); Name = name; Type = type; Nullable = nullable; AddPreReqCommand(prereqCommand); }
/// <summary> /// Creates a complex property in the complex type being created by the passed in command /// </summary> /// <param name="name">The name of the new property</param> /// <param name="prereqCommand">Instance of CreateComplexTypeCommand; must be non null</param> /// <param name="type">The type of the property</param> /// <param name="nullable">Flag whether the property is nullable or not</param> internal CreateComplexTypePropertyCommand(string name, CreateComplexTypeCommand prereqCommand, string type, bool? nullable) : base(PrereqId) { ValidatePrereqCommand(prereqCommand); ValidateString(name); ValidateString(type); Name = name; Type = type; Nullable = nullable; AddPreReqCommand(prereqCommand); }
/// <summary> /// Change various aspects of the passed in Function Import. The passed in function import will be modified based on the /// other passed-in parameters (null is not ignored). /// </summary> /// <param name="ec"></param> /// <param name="fi"></param> /// <param name="function"></param> /// <param name="functionImportName"></param> /// <param name="prereqCommand"></param> internal ChangeFunctionImportCommand( ConceptualEntityContainer ec, FunctionImport fi, Function function, string functionImportName, BoolOrNone functionImportIsComposable, CreateComplexTypeCommand prereqCommand) { ValidatePrereqCommand(prereqCommand); CommandValidation.ValidateFunctionImport(fi); ValidateString(functionImportName); FunctionImport = fi; Function = function; EntityContainer = ec; FunctionImportName = functionImportName; FunctionImportIsComposable = functionImportIsComposable; ChangeReturnType = true; _efContainerToBeNormalized = new List <EFContainer>(); AddPreReqCommand(prereqCommand); }
/// <summary> /// Change various aspects of the passed in Function Import. The passed in function import will be modified based on the /// other passed-in parameters (null is not ignored). /// </summary> /// <param name="ec"></param> /// <param name="fi"></param> /// <param name="function"></param> /// <param name="functionImportName"></param> /// <param name="prereqCommand"></param> internal ChangeFunctionImportCommand( ConceptualEntityContainer ec, FunctionImport fi, Function function, string functionImportName, BoolOrNone functionImportIsComposable, CreateComplexTypeCommand prereqCommand) { ValidatePrereqCommand(prereqCommand); CommandValidation.ValidateFunctionImport(fi); ValidateString(functionImportName); FunctionImport = fi; Function = function; EntityContainer = ec; FunctionImportName = functionImportName; FunctionImportIsComposable = functionImportIsComposable; ChangeReturnType = true; _efContainerToBeNormalized = new List<EFContainer>(); AddPreReqCommand(prereqCommand); }
/// <summary> /// This helper function will create a complex type using default name. /// 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 committed. /// </summary> /// <param name="cpc"></param> /// <returns>The new ComplexType</returns> internal static ComplexType CreateComplexTypeWithDefaultName(CommandProcessorContext cpc) { var service = cpc.EditingContext.GetEFArtifactService(); var artifact = service.Artifact; // the model that we want to add the complex type to var model = artifact.ConceptualModel(); if (model == null) { throw new CannotLocateParentItemException(); } var complexTypeName = ModelHelper.GetUniqueNameWithNumber(typeof(ComplexType), model, Resources.Model_DefaultComplexTypeName); // go create it var cp = new CommandProcessor(cpc); var cmd = new CreateComplexTypeCommand(complexTypeName, false); cp.EnqueueCommand(cmd); cp.Invoke(); return(cmd.ComplexType); }
/// <summary> /// Add a list of commands to create a ComplexType matching the list of columns passed in. /// Return the initial CreateComplexTypeCommand. /// </summary> /// <param name="sModel"></param> /// <param name="complexTypeName"></param> /// <param name="columns"></param> /// <param name="commands"></param> internal static CreateComplexTypeCommand AddCreateComplexTypeCommands( StorageEntityModel sModel, string complexTypeName, IList<IRawDataSchemaColumn> columns, IList<Command> commands) { Debug.Assert(false == String.IsNullOrEmpty(complexTypeName), "The passed in complexTypeName is null or empty"); Debug.Assert(null != columns, "The passed in schema columns are null"); Debug.Assert(null != commands, "We require a pre-created list of commands to add to"); CreateComplexTypeCommand cmdNewComplexType = null; if (!string.IsNullOrEmpty(complexTypeName) && null != columns && null != commands) { cmdNewComplexType = new CreateComplexTypeCommand(complexTypeName, true); commands.Add(cmdNewComplexType); // now add commands to add appropriate properties to the ComplexType foreach (var column in columns) { // adds commands to create and set the facets for a new complex type property to match the column AddCreateComplexTypePropertyCommands(sModel, column, cmdNewComplexType, null, commands); } } return cmdNewComplexType; }
/// <summary> /// This helper function will create a complex type using default name. /// 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> /// <returns>The new ComplexType</returns> internal static ComplexType CreateComplexTypeWithDefaultName(CommandProcessorContext cpc) { var service = cpc.EditingContext.GetEFArtifactService(); var artifact = service.Artifact; // the model that we want to add the complex type to var model = artifact.ConceptualModel(); if (model == null) { throw new CannotLocateParentItemException(); } var complexTypeName = ModelHelper.GetUniqueNameWithNumber(typeof(ComplexType), model, Resources.Model_DefaultComplexTypeName); // go create it var cp = new CommandProcessor(cpc); var cmd = new CreateComplexTypeCommand(complexTypeName, false); cp.EnqueueCommand(cmd); cp.Invoke(); return cmd.ComplexType; }
public void FunctionImportReturnComplexType() { UITestRunner.Execute(TestContext.TestName, () => { const string testName = "UndoRedo.FunctionImportReturnComplexType"; ExecuteUndoRedoTest( testName, "NorthwindModel.edmx", (commandProcessorContext, artifact) => { var dte = VsIdeTestHostContext.Dte; var commandProcessor = new CommandProcessor(commandProcessorContext); var createComplexTypeCmd = new CreateComplexTypeCommand("Sales_by_year_result", true); commandProcessor.EnqueueCommand(createComplexTypeCmd); commandProcessor.EnqueueCommand( new CreateComplexTypePropertyCommand("Column1", createComplexTypeCmd, "Int32", false)); commandProcessor.EnqueueCommand( new CreateFunctionImportCommand( artifact.GetFreshConceptualEntityContainer("NorthwindEntities"), artifact.GetFreshStorageFunction("Sales_by_Year"), "myfunctionimport", createComplexTypeCmd)); commandProcessor.Invoke(); Assert.IsNotNull(artifact.GetFreshComplexType("Sales_by_year_result")); Assert.IsNotNull(artifact.GetFreshComplexType("Sales_by_year_result")); Assert.IsNotNull(artifact.GetFreshFunctionImport("myfunctionimport")); Assert.AreEqual( "Collection(NorthwindModel.Sales_by_year_result)", ((SingleItemBinding<ComplexType>)artifact.GetFreshFunctionImport("myfunctionimport").ReturnType) .RefName); //Undo Redo Create FunctionImport dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), UndoCommand); Assert.IsNull(artifact.GetFreshComplexType("Sales_by_year_result")); Assert.IsNull(artifact.GetFreshFunctionImport("myfunctionimport")); dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), RedoCommand); Assert.IsNotNull(artifact.GetFreshComplexType("Sales_by_year_result")); Assert.IsNotNull(artifact.GetFreshFunctionImport("myfunctionimport")); Assert.AreEqual( "Collection(NorthwindModel.Sales_by_year_result)", ((SingleItemBinding<ComplexType>)artifact.GetFreshFunctionImport("myfunctionimport").ReturnType) .RefName); CommandProcessor.InvokeSingleCommand( commandProcessorContext, new CreateFunctionImportCommand( artifact.GetFreshConceptualEntityContainer("NorthwindEntities"), artifact.GetFreshStorageFunction("GetFreightCost"), "myfunctionimport2", "String")); Assert.IsNotNull(artifact.GetFreshFunctionImport("myfunctionimport2")); Assert.AreEqual( "Collection(String)", ((DefaultableValue<String>)artifact.GetFreshFunctionImport("myfunctionimport2").ReturnType).Value); createComplexTypeCmd = new CreateComplexTypeCommand("GetFreightCost_result", true); commandProcessor.EnqueueCommand(createComplexTypeCmd); commandProcessor.EnqueueCommand( new ChangeFunctionImportCommand( artifact.GetFreshConceptualEntityContainer("NorthwindEntities"), artifact.GetFreshFunctionImport("myfunctionimport2"), artifact.GetFreshStorageFunction("GetFreightCost"), "test123", /* isComposable */ BoolOrNone.FalseValue, createComplexTypeCmd)); commandProcessor.Invoke(); Assert.IsNull(artifact.GetFreshFunctionImport("myfunctionimport2")); Assert.IsNotNull(artifact.GetFreshFunctionImport("test123")); Assert.AreEqual( "Collection(NorthwindModel.GetFreightCost_result)", ((SingleItemBinding<ComplexType>)artifact.GetFreshFunctionImport("test123").ReturnType).RefName); Assert.IsNotNull(artifact.GetFreshComplexType("GetFreightCost_result")); // Undo redo "Change FunctionImport" dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), UndoCommand); Assert.IsNull(artifact.GetFreshFunctionImport("test123")); Assert.IsNotNull(artifact.GetFreshFunctionImport("myfunctionimport2")); Assert.AreEqual( "Collection(String)", ((DefaultableValue<String>)artifact.GetFreshFunctionImport("myfunctionimport2").ReturnType).Value); dte.ExecuteCommandForOpenDocument(artifact.LocalPath(), RedoCommand); Assert.IsNull(artifact.GetFreshFunctionImport("myfunctionimport2")); Assert.IsNotNull(artifact.GetFreshFunctionImport("test123")); Assert.AreEqual( "Collection(NorthwindModel.GetFreightCost_result)", ((SingleItemBinding<ComplexType>)artifact.GetFreshFunctionImport("test123").ReturnType).RefName); Assert.IsNotNull(artifact.GetFreshComplexType("GetFreightCost_result")); }); }); }
protected override void InvokeInternal(CommandProcessorContext cpc) { var artifact = cpc.EditingContext.GetEFArtifactService().Artifact; if (null == artifact) { Debug.Fail("null artifact not allowed"); return; } // safety check, this should never be hit Debug.Assert(_schemaProcedure != null, "InvokeInternal is called when _schemaProcedure is null"); if (null == _schemaProcedure) { throw new InvalidOperationException("InvokeInternal is called when _schemaProcedure is null."); } var cModel = artifact.ConceptualModel(); if (null == cModel) { Debug.Fail("ConceptualEntityModel not allowed"); return; } var cContainer = cModel.FirstEntityContainer as ConceptualEntityContainer; if (null == cContainer) { Debug.Fail("ConceptualEntityContainer not allowed"); return; } var sModel = artifact.StorageModel(); if (null == sModel) { Debug.Fail("null StorageEntityModel not allowed"); return; } // determine matching Function var funcObj = DatabaseObject.CreateFromSchemaProcedure(_schemaProcedure); var function = ModelHelper.FindFunction(sModel, funcObj); if (null == function) { // in some error scenarios where the model has not been properly created we can be asked to create a FunctionImport for a Function which does not exist // if so just return without creating return; } // do not produce FunctionImports for composable Functions unless _shouldCreateComposableFunctionImport is true if (false == _shouldCreateComposableFunctionImport && function.IsComposable.Value) { return; } // determine FunctionImport name and make sure it is unique var functionImportName = OverrideNameValue; if (String.IsNullOrWhiteSpace(functionImportName)) { if (null == function.LocalName || string.IsNullOrEmpty(function.LocalName.Value)) { Debug.Fail("null or empty LocalName attribute for matching Function " + function); return; } functionImportName = ModelHelper.GetUniqueName(typeof(FunctionImport), cContainer, function.LocalName.Value); } else { #if DEBUG string errorMessage; var isUnique = ModelHelper.IsUniqueName(typeof(FunctionImport), cContainer, functionImportName, false, out errorMessage); Debug.Assert(isUnique, "If we gave CreateMatchingFunctionImportCommand a name, it should have been unique"); #endif } object returnType = null; ComplexType existingComplexTypeReturnType = null; if (OverrideReturnTypeValue == null) { // get return type of the Function returnType = ConstructReturnType(_schemaProcedure, cModel, sModel, functionImportName); if (null == returnType) { Debug.Fail("cannot determine return type for schemaProcedure " + _schemaProcedure); return; } } else { if (OverrideReturnTypeValue.Equals(ModelConstants.NoneValue, StringComparison.Ordinal)) { returnType = Resources.NoneDisplayValueUsedForUX; } else { var rawValue = ModelHelper.UnwrapCollectionAroundFunctionImportReturnType(OverrideReturnTypeValue); // Here we attempt to find the corresponding ReturnType for the given ReturnTypeOverride. // The ReturnTypeOverride will be specified as the actual XAttribute value of the return type if (OverrideEntitySetValue != null) { if (ModelHelper.FindEntitySet(cpc.Artifact.ConceptualModel(), OverrideEntitySetValue) != null) { // ReturnType is an EntityType returnType = ModelHelper.FindEntityTypeViaSymbol(cpc.Artifact.ConceptualModel(), rawValue); } } else if (!ModelHelper.AllPrimitiveTypes(artifact.SchemaVersion).Contains(rawValue)) { // ReturnType is a ComplexType existingComplexTypeReturnType = ModelHelper.FindComplexType(cpc.Artifact.ConceptualModel(), rawValue); returnType = existingComplexTypeReturnType; } else { returnType = rawValue; } } } // Composable functions that do not return collections (e.g. scalar valued functions) are not supported // and should not be imported to the conceptual model if (Resources.NoneDisplayValueUsedForUX.Equals(returnType) && function.IsComposable.Value) { return; } // list of commands to be executed IList <Command> commands = new List <Command>(); // if return type is the name of a ComplexType then create a new matching ComplexType CreateComplexTypeCommand createComplexTypeCommand = null; if (OverrideReturnTypeValue == null && returnType is string && false == Resources.NoneDisplayValueUsedForUX.Equals(returnType)) { createComplexTypeCommand = AddCreateComplexTypeCommands(sModel, returnType as string, _schemaProcedure.RawColumns, commands); } // if we created a ComplexType above then pass that as a pre-req to the CreateFunctionImport command, // otherwise just create the FunctionImport without the pre-req CreateFunctionImportCommand cmdFuncImp; if (createComplexTypeCommand == null) { if (returnType is EdmType) { // For the case where the FunctionImport should have a return type which is not a Complex Type but // simply a C-side primitive type we have to pass the _name_ of the C-side primitive type to // CreateFunctionImportCommand, rather than the type itself returnType = (returnType as EdmType).Name; } cmdFuncImp = new CreateFunctionImportCommand(cContainer, function, functionImportName, returnType); } else { cmdFuncImp = new CreateFunctionImportCommand(cContainer, function, functionImportName, createComplexTypeCommand); } commands.Add(cmdFuncImp); // now create the FunctionImportMapping to map the S-side Function to the C-side FunctionImport if (null != artifact.MappingModel() && null != artifact.MappingModel().FirstEntityContainerMapping) { var cmdFuncImpMapping = new CreateFunctionImportMappingCommand( artifact.MappingModel().FirstEntityContainerMapping, function, cmdFuncImp.Id); cmdFuncImpMapping.AddPreReqCommand(cmdFuncImp); commands.Add(cmdFuncImpMapping); IDictionary <string, string> mapPropertyNameToColumnName = null; if (_schemaProcedure != null) { mapPropertyNameToColumnName = ModelHelper.ConstructComplexTypePropertyNameToColumnNameMapping( _schemaProcedure.RawColumns.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 (OverrideReturnTypeValue != null && existingComplexTypeReturnType != null) { commands.Add( new CreateFunctionImportTypeMappingCommand(cmdFuncImpMapping, existingComplexTypeReturnType) { CreateDefaultScalarProperties = true, PropertyNameToColumnNameMap = mapPropertyNameToColumnName }); } } // now invoke the list of commands if (null != commands) { var cp = new CommandProcessor(cpc, commands); cp.Invoke(); // assign the generated FunctionImport so this command can be used as input for others _generatedFunctionImport = cmdFuncImp.FunctionImport; } }
/// <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); } } } }