/// <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); }
/// <summary> /// Creates new ComplexTypeMapping inside specified FunctionImportMapping /// </summary> /// <param name="functionImportMapping"></param> /// <param name="complexType"></param> internal CreateFunctionImportTypeMappingCommand(FunctionImportMapping functionImportMapping, ComplexType complexType) : base(PrereqId) { CommandValidation.ValidateFunctionImportMapping(functionImportMapping); CommandValidation.ValidateComplexType(complexType); _functionImportMapping = functionImportMapping; _complexType = complexType; }
/// <summary> /// Creates new EntityTypeMapping inside specified FunctionImportMapping /// </summary> /// <param name="functionImportMapping"></param> /// <param name="entityType"></param> internal CreateFunctionImportTypeMappingCommand(FunctionImportMapping functionImportMapping, EntityType entityType) : base(PrereqId) { CommandValidation.ValidateFunctionImportMapping(functionImportMapping); CommandValidation.ValidateEntityType(entityType); _functionImportMapping = functionImportMapping; _entityType = entityType; }
private void WriteFunctionImportMappingStartElement(FunctionImportMapping functionImportMapping) { _xmlWriter.WriteStartElement(MslConstructs.FunctionImportMappingElement); _xmlWriter.WriteAttributeString( MslConstructs.FunctionImportMappingFunctionNameAttribute, functionImportMapping.TargetFunction.FullName); _xmlWriter.WriteAttributeString( MslConstructs.FunctionImportMappingFunctionImportNameAttribute, functionImportMapping.FunctionImport.Name); }
protected override void InvokeInternal(CommandProcessorContext cpc) { // safety check, this should never be hit Debug.Assert( _function != null && _functionImport != null, "InvokeInternal is called when _function or _function import is null."); if (_function == null || _functionImport == null) { throw new InvalidOperationException("InvokeInternal is called when _function or _function import is null."); } _fim = _functionImport.FunctionImportMapping; _fim.FunctionName.SetRefName(_function); XmlModelHelper.NormalizeAndResolve(_fim); }
private void CreateFunctionMappingComplexTypeMapping(CommandEntity entity, FunctionImportMapping importMapping) { //<ResultMapping> // <ComplexTypeMapping TypeName="PetShopModel.GetCategoryById_Result"> string entityName = String.Concat(entity.Name, "Result"); var mapping = importMapping.ResultMapping != null && importMapping.ResultMapping.ComplexTypeMappings != null ? importMapping.ResultMapping.ComplexTypeMappings.FirstOrDefault() : null; if (mapping == null) { importMapping.ResultMapping = new FunctionImportMappingResultMapping() { ComplexTypeMappings = new List <FunctionImportComplexTypeMapping>() }; mapping = new FunctionImportComplexTypeMapping() { TypeName = String.Concat(ConceptualSchema.Namespace, ".", entityName) }; importMapping.ResultMapping.ComplexTypeMappings.Add(mapping); } else if (!String.IsNullOrEmpty(mapping.TypeName)) { entityName = mapping.TypeName.Replace("IsTypeOf(", "").Replace(String.Format("{0}.", ConceptualSchema.Namespace), "").Replace(")", ""); entityName = entityName.Equals(entity.Name, StringComparison.OrdinalIgnoreCase) ? entity.Name : entityName; } if (ConceptualSchema.ComplexTypes.Count(c => c.Name.Equals(entityName, StringComparison.OrdinalIgnoreCase)) == 0) { entityName = String.Concat(entity.Name, "Result"); } // Check for inheritance. mapping.TypeName = String.Format("{0}.{1}", ConceptualSchema.Namespace, entityName); _mappingEntityNames.Add(entity.EntityKey(), importMapping.FunctionImportName); _mappingEntityNames.Add(entity.EntityKey() + "complex", entityName); //<ComplexTypeMapping TypeName="PetShopModel.GetCategoryById_Result"> // <ScalarProperty Name="CategoryId" ColumnName="CategoryId" /> // <ScalarProperty Name="Name" ColumnName="Name" /> // <ScalarProperty Name="Description" ColumnName="Descn" /> //</ComplexTypeMapping> MergeScalarProperties(mapping, entity); }
protected override void ProcessPreReqCommands() { var preregCommand1 = GetPreReqCommand(CreateFunctionImportMappingCommand.PrereqId) as CreateFunctionImportMappingCommand; if (preregCommand1 != null) { _functionImportMapping = preregCommand1.FunctionImportMapping; Debug.Assert( _functionImportMapping != null, "CreateFunctionImportMappingCommand command return null value of _functionImportMapping"); } var preregCommand2 = GetPreReqCommand(CreateComplexTypeCommand.PrereqId) as CreateComplexTypeCommand; if (preregCommand2 != null) { _complexType = preregCommand2.ComplexType; Debug.Assert(_complexType != null, "CreateComplexTypeCommand command return null value of ComplexType"); } }
protected override void InvokeInternal(CommandProcessorContext cpc) { // safety check, this should never be hit Debug.Assert( Function != null && FunctionImport != null && ContainerMapping != null, "InvokeInternal is called when Function or FunctionImport or ContainerMapping is null."); if (Function == null || FunctionImport == null || ContainerMapping == null) { throw new InvalidOperationException("InvokeInternal is called when Function or FunctionImport or ContainerMapping is null."); } _fim = new FunctionImportMapping(ContainerMapping, null); _fim.FunctionImportName.SetRefName(FunctionImport); _fim.FunctionName.SetRefName(Function); ContainerMapping.AddFunctionImportMapping(_fim); XmlModelHelper.NormalizeAndResolve(_fim); }
internal static void ValidateFunctionImportMapping(FunctionImportMapping functionImportMapping) { ValidateEFElement(functionImportMapping); }
public MappingFunctionImport(EditingContext context, FunctionImportMapping functionImportMapping, MappingEFElement parent) : base(context, functionImportMapping, parent) { }
/// <summary> /// Adds a mapping between a model function and a store function. /// </summary> /// <param name="modelFunction">Model function import to map.</param> /// <param name="storeFunction">Store function to map the model function to.</param> /// <returns>A FunctionImportMapping object representing the new mapping.</returns> public FunctionImportMapping AddMapping(ModelFunction modelFunction, StoreFunction storeFunction) { FunctionImportMapping fim = new FunctionImportMapping(base.ParentFile, _entityContainerMapping, this, modelFunction, storeFunction); _functionImportMappings.Add(fim.ModelFunction.Name, fim); fim.Removed += new EventHandler(fim_Removed); fim.ModelFunction.NameChanged += new EventHandler<NameChangeArgs>(ModelFunction_NameChanged); return fim; }
/// <summary> /// Delete the passed in function import mapping /// </summary> /// <param name="fim"></param> internal DeleteFunctionImportMappingCommand(FunctionImportMapping fim) : base(fim) { CommandValidation.ValidateFunctionImportMapping(fim); }
void Mapping_Removed(object sender, EventArgs e) { _mapping = null; }
private void WriteFunctionImportMappingStartElement(FunctionImportMapping functionImportMapping) { this._xmlWriter.WriteStartElement("FunctionImportMapping"); this._xmlWriter.WriteAttributeString("FunctionName", functionImportMapping.TargetFunction.FullName); this._xmlWriter.WriteAttributeString("FunctionImportName", functionImportMapping.FunctionImport.Name); }
private void CreateFunctionMappingEntity(CommandEntity entity) { if (!Configuration.Instance.IncludeFunctions || entity.IsFunction || _mappingEntitys.Contains(entity.Name)) { Debug.WriteLine(String.Format("Already Processed Mapping Model Entity {0}", entity.Name), MappingCategory); return; } // <FunctionImportMapping FunctionImportName="GetCategoryById" FunctionName="PetShopModel.Store.GetCategoryById" > #region Validate that an EntitySet Exists in the MappingStorageContainer. var importMapping = MappingEntityContainer.FunctionImportMappings.Where(e => entity.Name.Equals(e.FunctionImportName, StringComparison.OrdinalIgnoreCase) || // Safe Name. entity.EntityKeyName.Equals(e.FunctionImportName, StringComparison.OrdinalIgnoreCase) || // Database Name. (e.ResultMapping != null && e.ResultMapping.ComplexTypeMappings.Count > 0 && (e.ResultMapping.ComplexTypeMappings.Count(et => et.TypeName.Equals(String.Concat(ConceptualSchema.Namespace, ".", entity.Name), StringComparison.OrdinalIgnoreCase)) > 0 || e.ResultMapping.ComplexTypeMappings.Count(et => et.TypeName.Equals(String.Concat(ConceptualSchema.Namespace, ".", entity.Name, "Result"), StringComparison.OrdinalIgnoreCase)) > 0 || e.ResultMapping.ComplexTypeMappings.Count(et => et.TypeName.Equals(String.Concat(ConceptualSchema.Namespace, ".", entity.EntityKeyName), StringComparison.OrdinalIgnoreCase)) > 0 || e.ResultMapping.ComplexTypeMappings.Count(et => et.TypeName.Equals(String.Concat(ConceptualSchema.Namespace, ".", entity.EntityKeyName, "Result"), StringComparison.OrdinalIgnoreCase)) > 0))).FirstOrDefault(); //NOTE: We could also possibly look up the table name by looking at the StorageModel's EntitySet Tables Property. // If the Entity Set does not exist than create a new one. if (importMapping == null) { importMapping = new FunctionImportMapping { FunctionImportName = entity.Name, ResultMapping = new FunctionImportMappingResultMapping() }; MappingEntityContainer.FunctionImportMappings.Add(importMapping); } importMapping.FunctionName = String.Concat(StorageSchema.Namespace, ".", entity.EntityKeyName); if (String.IsNullOrEmpty(importMapping.FunctionImportName) || !ConceptualSchemaEntityContainer.FunctionImports.Exists(importMapping.FunctionImportName)) { importMapping.FunctionImportName = entity.Name; } #endregion if (entity.IsStronglyTypedAssociatedEntity) { if (importMapping.ResultMapping != null && importMapping.ResultMapping.ComplexTypeMappings != null) { importMapping.ResultMapping.ComplexTypeMappings = null; } CreateFunctionMappingEntityTypeMapping(entity, importMapping); } else if (entity.Properties.Count > 0) { CreateFunctionMappingComplexTypeMapping(entity, importMapping); } else if (importMapping.ResultMapping != null && importMapping.ResultMapping.ComplexTypeMappings != null) { importMapping.ResultMapping.ComplexTypeMappings.Clear(); } _mappingEntitys.Add(entity.Name); }