/// <summary> /// Regenerating the SSDL can sometimes cause existing S-side objects to be renamed. /// In this case, ensure that the references to those old S-side objects from /// the MSL are updated to the new names. /// </summary> private static void RetargetMappingsForRenamedStorageObjects( StorageEntityModel preExistingStorageEntityModel, StorageEntityModel newStorageEntityModel) { Debug.Assert( null != preExistingStorageEntityModel, "Null preExistingStorageEntityModel in ReplaceSsdlCommand.RetargetMappingsForRenamedStorageObjects()"); Debug.Assert( null != newStorageEntityModel, "Null newStorageEntityModel in ReplaceSsdlCommand.RetargetMappingsForRenamedStorageObjects()"); if (null == preExistingStorageEntityModel || null == newStorageEntityModel) { return; } // re-target the mappings which reference Functions RetargetMappingsForRenamedStorageFunctions(preExistingStorageEntityModel, newStorageEntityModel); // re-target the mappings which reference EntitySets var preExistingStorageEntityContainer = preExistingStorageEntityModel.FirstEntityContainer as StorageEntityContainer; var newStorageEntityEntityContainer = newStorageEntityModel.FirstEntityContainer as StorageEntityContainer; RetargetMappingsForRenamedStorageEntitySets(preExistingStorageEntityContainer, newStorageEntityEntityContainer); // Note: DO NOT normalize and resolve the Mapping Model yet - this needs to happen // once the SSDL has been replaced. }
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); } }
/// <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); }
private void RecordFunctions(StorageEntityModel sem) { foreach (var f in sem.Functions()) { var dbObj = DatabaseObject.CreateFromFunction(f); _allFunctions.Add(dbObj, f.LocalName.Value); } }
public ExplorerStorageEntityModel(EditingContext context, StorageEntityModel entityModel, ExplorerEFElement parent) : base(context, entityModel, parent) { _typesGhostNode = new ExplorerTypes( Resources.StorageTypesGhostNodeName, context, this); _funcsGhostNode = new ExplorerFunctions( Resources.StorageFunctionsGhostNodeName, context, this); _assocsGhostNode = new ExplorerAssociations( Resources.StorageAssociationsGhostNodeName, context, this); }
public ExplorerStorageEntityModel(EditingContext context, StorageEntityModel entityModel, ExplorerEFElement parent) : base(context, entityModel, parent) { _typesGhostNode = new ExplorerTypes( Resources.StorageTypesGhostNodeName, context, this); _funcsGhostNode = new ExplorerFunctions( Resources.StorageFunctionsGhostNodeName, context, this); _assocsGhostNode = new ExplorerAssociations( Resources.StorageAssociationsGhostNodeName, context, this); }
public void GetStoragePrimitiveType_returns_type_name_for_valid_type() { var ssdl = XElement.Parse( "<Schema Namespace=\"Model.Store\" Provider=\"System.Data.SqlClient\" ProviderManifestToken=\"2008\" Alias=\"Self\" xmlns=\"http://schemas.microsoft.com/ado/2009/11/edm/ssdl\" />"); using (var storageModel = new StorageEntityModel(null, ssdl)) { Assert.Equal( "tinyint", storageModel.GetStoragePrimitiveType("tinyint").Name); } }
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 storageModel = new StorageEntityModel(entityDesignArtifactMock.Object, element)) { Assert.Same(element.Name.Namespace, storageModel.XNamespace); } }
internal override Dictionary <MappingLovEFElement, string> GetListOfValues(ListOfValuesCollection type) { var lov = new Dictionary <MappingLovEFElement, string>(); Debug.Assert(type == ListOfValuesCollection.FirstColumn, "Unsupported lov type was sent"); if (type == ListOfValuesCollection.FirstColumn) { StorageEntityModel storageModel = null; if (Function != null) { storageModel = Function.EntityModel; } else { // this is a creator node, so get the list from the artifact var entity = MappingFunctionEntityType.ModelItem as EntityType; storageModel = entity.Artifact.StorageModel(); } if (Function != null) { // add the row at the top that the user can click on to remove the item lov.Add(LovDeletePlaceHolder, LovDeletePlaceHolder.DisplayName); } var functions = new List <Function>(); functions.AddRange(storageModel.Functions()); if (functions.Count == 0) { if (Function == null) { lov.Add(LovEmptyPlaceHolder, LovEmptyPlaceHolder.DisplayName); } } else { // add those remaining in our list foreach (var func in functions) { // adding the Function to the list lov.Add(new MappingLovEFElement(func, func.DisplayName), func.DisplayName); } } return(lov); } return(base.GetListOfValues(type)); }
public void StoreTypeNameToStoreTypeMap_returns_type_map() { var ssdl = XElement.Parse( "<Schema Namespace=\"Model.Store\" Provider=\"System.Data.SqlClient\" ProviderManifestToken=\"2008\" Alias=\"Self\" xmlns=\"http://schemas.microsoft.com/ado/2009/11/edm/ssdl\" />"); using (var storageModel = new StorageEntityModel(null, ssdl)) { var typeMap = storageModel.StoreTypeNameToStoreTypeMap; Assert.Equal( SqlProviderServices.Instance.GetProviderManifest("2008").GetStoreTypes().Select(t => t.Name), typeMap.Keys); Assert.False(typeMap.Any(t => t.Key != t.Value.Name)); } }
/// <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); } } }
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); } }
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); }
private static void RetargetMappingsForRenamedStorageFunctions( StorageEntityModel preExistingStorageEntityModel, StorageEntityModel newStorageEntityModel) { if (null == preExistingStorageEntityModel || null == newStorageEntityModel) { return; } // find all mappings from database identity to S-side Functions for the new artifact var newArtifactSSideMappings = ConstructDatabaseObjectToFunctionMappings(newStorageEntityModel); // find all mappings from database identity to S-side Functions for the existing artifact var existingArtifactSSideMappings = ConstructDatabaseObjectToFunctionMappings(preExistingStorageEntityModel); // find all Functions whose name has changed (but whose identity has stayed the same) // and update the name part of any ItemBinding which references the old name UpdateOldDatabaseObjectReferencesToNewNames(existingArtifactSSideMappings, newArtifactSSideMappings); }
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); } }
public void XNamespace_returns_root_namespace_if_element_null() { var tmpElement = new XElement("{http://schemas.microsoft.com/ado/2009/11/edm/ssdl}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 storageModel = new StorageEntityModel(enityDesignArtifiact, tmpElement)) { storageModel.SetXObject(null); Assert.Equal("http://schemas.microsoft.com/ado/2009/11/edm/ssdl", storageModel.XNamespace); // resetting the element is required for clean up storageModel.SetXObject(tmpElement); } }
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); } }
/// <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); } } } }
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(); } }
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; }
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; }
internal StorageEntityType(StorageEntityModel model, XElement element) : base(model, element) { }
/// <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; }
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; } }
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(); } }
private void Initialize(StorageEntityModel sem) { // initialize S-side facet default values from runtime for all valid S-side Property types _sSideFacetDefaults = new Dictionary <string, IDictionary <string, object> >(); var allStoreSideTypes = sem.StoreTypeNameToStoreTypeMap.Values; foreach (var sSidePrimitiveType in allStoreSideTypes) { // fill out S-side facets defaults var sSideTypeMap = _sSideFacetDefaults[sSidePrimitiveType.Name] = new Dictionary <string, object>(); var sSideTypeUsage = TypeUsage.CreateDefaultTypeUsage(sSidePrimitiveType); Debug.Assert(null != sSideTypeUsage, "null sSideTypeUsage for sSidePrimitiveType " + sSidePrimitiveType.FullName); if (null != sSideTypeUsage) { foreach (var facet in sSideTypeUsage.Facets) { var fd = facet.Description; if (null != fd) { var name = fd.FacetName; var defaultValue = fd.DefaultValue; // Special treatment for MaxLength facet. The default for MaxLength for some S-side types // is int.MaxValue or int.MaxValue/2. If the S-side is defaulted we should really propagate // the value "Max" instead. So override here. if (Property.AttributeMaxLength.Equals(name, StringComparison.Ordinal)) { // value could be an Int32 or a string - but need to pass in as a UInt32 to ModelHelper.GetMaxLengthFacetValue() uint defaultValueAsUInt; if (null != defaultValue && uint.TryParse(defaultValue.ToString(), out defaultValueAsUInt)) { defaultValue = ModelHelper.GetMaxLengthFacetValue(defaultValueAsUInt); } } sSideTypeMap[name] = defaultValue; } } } } // initialize C-side facet default values from runtime for all valid C-side Property types _cSideFacetDefaults = new Dictionary <string, IDictionary <string, object> >(); var edmCollection = new EdmItemCollection(new XmlReader[] { }); foreach (var cSidePrimitiveType in edmCollection.GetPrimitiveTypes()) { // fill out C-side facets defaults var cSideTypeMap = _cSideFacetDefaults[cSidePrimitiveType.Name] = new Dictionary <string, object>(); var cSideTypeUsage = TypeUsage.CreateDefaultTypeUsage(cSidePrimitiveType); Debug.Assert(null != cSideTypeUsage, "null cSideTypeUsage for cSidePrimitiveType " + cSidePrimitiveType.FullName); if (null != cSideTypeUsage) { foreach (var facet in cSideTypeUsage.Facets) { var fd = facet.Description; if (null != fd) { var name = fd.FacetName; var defaultValue = fd.DefaultValue; cSideTypeMap[name] = defaultValue; } } } } // initialize the list of facet-synchronizers _facetSynchronizers = new List <SynchronizeConceptualFacet>(); // add the synchronizer for Precision _facetSynchronizers.Add( (storageProperty, conceptualProperty) => SynchronizeFacet( storageProperty.TypeName, storageProperty.Precision, conceptualProperty.TypeName, conceptualProperty.Precision)); // add the synchronizer for Scale _facetSynchronizers.Add( (storageProperty, conceptualProperty) => SynchronizeFacet( storageProperty.TypeName, storageProperty.Scale, conceptualProperty.TypeName, conceptualProperty.Scale)); // add the synchronizer for MaxLength _facetSynchronizers.Add( (storageProperty, conceptualProperty) => SynchronizeFacet( storageProperty.TypeName, storageProperty.MaxLength, conceptualProperty.TypeName, conceptualProperty.MaxLength)); // add the synchronizer for Nullable _facetSynchronizers.Add( (storageProperty, conceptualProperty) => SynchronizeFacet( storageProperty.TypeName, storageProperty.Nullable, conceptualProperty.TypeName, conceptualProperty.Nullable)); // add the synchronizer for Unicode _facetSynchronizers.Add( (storageProperty, conceptualProperty) => SynchronizeFacet( storageProperty.TypeName, storageProperty.Unicode, conceptualProperty.TypeName, conceptualProperty.Unicode)); // add the synchronizer for FixedLength _facetSynchronizers.Add( (storageProperty, conceptualProperty) => SynchronizeFacet( storageProperty.TypeName, storageProperty.FixedLength, conceptualProperty.TypeName, conceptualProperty.FixedLength)); }
/// <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); } } } }
internal ReplaceSsdlCommand(StorageEntityModel newArtifactStorageEntityModel) { Debug.Assert(null != newArtifactStorageEntityModel, "received null newArtifactStorageEntityModel in constructor"); _newArtifactStorageEntityModel = newArtifactStorageEntityModel; }
protected override void InvokeInternal(CommandProcessorContext cpc) { // check that we have an existing artifact var service = cpc.EditingContext.GetEFArtifactService(); var existingArtifact = service.Artifact as EntityDesignArtifact; Debug.Assert(existingArtifact != null, "Null Artifact"); if (null == existingArtifact) { return; } // check that the _new_ artifact's StorageEntityModel exists and has an underlying XObject if (null == _newArtifactStorageEntityModel || null == _newArtifactStorageEntityModel.XObject) { Debug.Fail("new artifact StorageModel was null or has null XObject"); return; } // save off the old storage model namespace, the old storage Entity Model // and the old storage Entity Container name string previousStorageModelNamespace = null; StorageEntityModel previousStorageEntityModel = null; string previousStorageEntityContainerName = null; if (null != existingArtifact.StorageModel) { previousStorageEntityModel = existingArtifact.StorageModel; if (null != previousStorageEntityModel.Namespace && !string.IsNullOrEmpty(previousStorageEntityModel.Namespace.Value)) { previousStorageModelNamespace = previousStorageEntityModel.Namespace.Value; } if (null != previousStorageEntityModel.FirstEntityContainer && null != previousStorageEntityModel.FirstEntityContainer.LocalName && !string.IsNullOrEmpty(previousStorageEntityModel.FirstEntityContainer.LocalName.Value)) { previousStorageEntityContainerName = previousStorageEntityModel.FirstEntityContainer.LocalName.Value; } } // for any S-side objects which have been renamed, re-target the MSL // which targets them in preparation for their replacement below RetargetMappingsForRenamedStorageObjects(previousStorageEntityModel, _newArtifactStorageEntityModel); // Recurse through the MappingModel updating any references to the old S-side Namespace // if different from the new one (must be done before SSDL is replaced which will // unbind all the references) if (existingArtifact.MappingModel != null && _newArtifactStorageEntityModel != null && _newArtifactStorageEntityModel.Namespace != null && !string.IsNullOrEmpty(_newArtifactStorageEntityModel.Namespace.Value) && !_newArtifactStorageEntityModel.Namespace.Value.Equals(previousStorageModelNamespace, StringComparison.CurrentCulture)) { RecursivelyReplaceStorageNamespaceRefs( existingArtifact.MappingModel, previousStorageModelNamespace, _newArtifactStorageEntityModel.Namespace.Value); } // replace the old SSDL with the new ReplaceSsdl(cpc, existingArtifact, _newArtifactStorageEntityModel.XElement); // update the Mapping Model to reference the new SSDL UpdateMappingModel(existingArtifact, previousStorageEntityContainerName); }
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); }
private static Dictionary <DatabaseObject, Function> ConstructDatabaseObjectToFunctionMappings(StorageEntityModel sem) { Debug.Assert(null != sem, "was passed a null StorageEntityModel"); var mappings = new Dictionary <DatabaseObject, Function>(); if (null != sem) { foreach (var func in sem.Functions()) { var dbObj = DatabaseObject.CreateFromFunction(func); mappings.Add(dbObj, func); } } return(mappings); }
private void RecordFunctions(StorageEntityModel sem) { foreach (var f in sem.Functions()) { var dbObj = DatabaseObject.CreateFromFunction(f); _allFunctions.Add(dbObj, f.LocalName.Value); } }
/// <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; } } }