src/Misc/EFTools/EntityDesignModel/Commands/ChangeFunctionImportCommand.cs
/// <summary>
///     Update function import return type if requested.
/// </summary>
Update function import return type if requested.
Update function import return type if requested .
private void UpdateFunctionImportReturnType(CommandProcessorContext cpc)
        {
            if (ChangeReturnType)
            {
                var complexType = ReturnSingleType as ComplexType;
                var entityType = ReturnSingleType as EntityType;
                var returnTypeStringValue = ReturnSingleType as string;
                var functionImportMapping = FunctionImport.FunctionImportMapping;
                if (functionImportMapping != null
                    && functionImportMapping.ResultMapping != null)
                {
                    foreach (var typeMapping in functionImportMapping.ResultMapping.TypeMappings().ToList())
                    {
                        if (typeMapping is FunctionImportComplexTypeMapping
                            && (complexType == null
                                || !String.Equals(typeMapping.TypeName.Target.DisplayName, 
                                                  complexType.DisplayName, StringComparison.CurrentCulture)))
                        {
                            DeleteEFElementCommand.DeleteInTransaction(cpc, typeMapping);
                        }
                        else if (typeMapping is FunctionImportEntityTypeMapping
                                 && (entityType == null
                                     || !String.Equals(typeMapping.TypeName.Target.DisplayName,
                                                       entityType.DisplayName, StringComparison.CurrentCulture)))
                        {
                            DeleteEFElementCommand.DeleteInTransaction(cpc, typeMapping);
                        }
                    }
                    if (functionImportMapping.ResultMapping.TypeMappings().Count == 0)
                    {
                        DeleteEFElementCommand.DeleteInTransaction(cpc, functionImportMapping.ResultMapping);
                    }
                }
                string updatedReturnTypeAsString = null;
                if (entityType != null)
                {
                    if (FunctionImport.ReturnTypeAsComplexType != null)
                    {
                        FunctionImport.ReturnTypeAsComplexType.SetRefName(null);
                        FunctionImport.ReturnTypeAsComplexType.Rebind();
                    }
                    Debug.Assert(entityType.EntitySet != null, "Entity Type doesn't have an Entity Set we can use for the Function Import");
                    if (entityType.EntitySet != null)
                    {
                        FunctionImport.EntitySet.SetRefName(entityType.EntitySet);
                        FunctionImport.EntitySet.Rebind();
                        FunctionImport.ReturnTypeAsEntityType.SetRefName(entityType);
                        FunctionImport.ReturnTypeAsEntityType.Rebind();
                    }
                }
                else if (complexType != null)
                {
                    if (FunctionImport.EntitySet.RefName != null)
                    {
                        FunctionImport.EntitySet.SetRefName(null);
                        FunctionImport.EntitySet.Rebind();
                    }
                    FunctionImport.ReturnTypeAsComplexType.SetRefName(complexType);
                    FunctionImport.ReturnTypeAsComplexType.Rebind();
                }
                else
                {
                    if (FunctionImport.ReturnTypeAsComplexType != null)
                    {
                        FunctionImport.ReturnTypeAsComplexType.SetRefName(null);
                        FunctionImport.ReturnTypeAsComplexType.Rebind();
                    }
                    if (FunctionImport.EntitySet.RefName != null)
                    {
                        FunctionImport.EntitySet.SetRefName(null);
                        FunctionImport.EntitySet.Rebind();
                    }
                    if (returnTypeStringValue != Tools.XmlDesignerBase.Resources.NoneDisplayValueUsedForUX)
                    {
                        updatedReturnTypeAsString = String.Format(
                            CultureInfo.InvariantCulture, FunctionImport.CollectionFormat, returnTypeStringValue);
                    }
                    FunctionImport.ReturnTypeAsPrimitiveType.Value = updatedReturnTypeAsString;
                }
            }
        }
private void UpdateFunctionImportReturnType ( CommandProcessorContext cpc ) { if ( ChangeReturnType ) { var complexType = ReturnSingleType as ComplexType ; var entityType = ReturnSingleType as EntityType ; var returnTypeStringValue = ReturnSingleType as string ; var functionImportMapping = FunctionImport . FunctionImportMapping ; if ( functionImportMapping != null && functionImportMapping . ResultMapping != null ) { foreach ( var typeMapping in functionImportMapping . ResultMapping . TypeMappings ( ) . ToList ( ) ) { if ( typeMapping is FunctionImportComplexTypeMapping && ( complexType == null || ! String . Equals ( typeMapping . TypeName . Target . DisplayName , complexType . DisplayName , StringComparison . CurrentCulture ) ) ) { DeleteEFElementCommand . DeleteInTransaction ( cpc , typeMapping ) ; } else if ( typeMapping is FunctionImportEntityTypeMapping && ( entityType == null || ! String . Equals ( typeMapping . TypeName . Target . DisplayName , entityType . DisplayName , StringComparison . CurrentCulture ) ) ) { DeleteEFElementCommand . DeleteInTransaction ( cpc , typeMapping ) ; } } if ( functionImportMapping . ResultMapping . TypeMappings ( ) . Count == 0 ) { DeleteEFElementCommand . DeleteInTransaction ( cpc , functionImportMapping . ResultMapping ) ; } } string updatedReturnTypeAsString = null ; if ( entityType != null ) { if ( FunctionImport . ReturnTypeAsComplexType != null ) { FunctionImport . ReturnTypeAsComplexType . SetRefName ( null ) ; FunctionImport . ReturnTypeAsComplexType . Rebind ( ) ; } Debug . Assert ( entityType . EntitySet != null , " " ) ; if ( entityType . EntitySet != null ) { FunctionImport . EntitySet . SetRefName ( entityType . EntitySet ) ; FunctionImport . EntitySet . Rebind ( ) ; FunctionImport . ReturnTypeAsEntityType . SetRefName ( entityType ) ; FunctionImport . ReturnTypeAsEntityType . Rebind ( ) ; } } else if ( complexType != null ) { if ( FunctionImport . EntitySet . RefName != null ) { FunctionImport . EntitySet . SetRefName ( null ) ; FunctionImport . EntitySet . Rebind ( ) ; } FunctionImport . ReturnTypeAsComplexType . SetRefName ( complexType ) ; FunctionImport . ReturnTypeAsComplexType . Rebind ( ) ; } else { if ( FunctionImport . ReturnTypeAsComplexType != null ) { FunctionImport . ReturnTypeAsComplexType . SetRefName ( null ) ; FunctionImport . ReturnTypeAsComplexType . Rebind ( ) ; } if ( FunctionImport . EntitySet . RefName != null ) { FunctionImport . EntitySet . SetRefName ( null ) ; FunctionImport . EntitySet . Rebind ( ) ; } if ( returnTypeStringValue != Tools . XmlDesignerBase . Resources . NoneDisplayValueUsedForUX ) { updatedReturnTypeAsString = String . Format ( CultureInfo . InvariantCulture , FunctionImport . CollectionFormat , returnTypeStringValue ) ; } FunctionImport . ReturnTypeAsPrimitiveType . Value = updatedReturnTypeAsString ; } } }
Update function import return type if requested.
Update function import return type if requested .
// figure out if we are using a complex type, an entity type, primitive type or none as the return type // if returnTypeStringValue is not null, the value could be "None" or the string representation of primitive types (for example: "string", "Int16"). // Only delete type-mapping if the function-import's return-type does not match type-mapping's type. // If the old type mapping is FunctionImportComplexTypeMapping and function import does not return a complex type // or return a different complex type. // If the old type mapping is FunctionImportEntityTypeMapping and function import does not return an entity type // or return a different entity type. // If ResultMapping does not contain any type mappings, delete it. // we won't do any equality checking here against the original function import's return type // because we would expend cycles determining the 'collection' string, etc. // Return type could be a collection of EntityType, ComplexType or primitive type. // If we change from the return type from a complex type to an entity type, we need to remove the complex type binding in the function import. // Check if complex type binding is not null and reset it. // if we are using an entity type, the return type is "Collection(entityType)" // if we change from an entity type to any other type, we need to remove the EntitySet binding on the FunctionImport // Return type could be a collection of EntityType, ComplexType or primitive type. // If we change from the return type from a complex type to a primitive type, we need to remove the complex type binding in the function import. // Check if complex type binding is not null and reset it. // if we change from an entity type to any other type, we need to remove the EntitySet binding on the FunctionImport // if the new value is 'None' then set the return type to null // update the actual return type of the function import
cpc
CommandProcessorContext