/// <summary>
        /// Add a function import to the entity container.
        /// </summary>
        /// <param name="serviceOperation">The service operation to add to the entity container.</param>
        /// <returns>The newly added or cached function import instance.</returns>
        internal IEdmOperationImport EnsureOperationImport(OperationWrapper serviceOperation)
        {
            Debug.Assert(serviceOperation != null, "serviceOperation != null");
            string functionImportName = serviceOperation.Name;

            Debug.Assert(!string.IsNullOrEmpty(functionImportName), "!string.IsNullOrEmpty(functionImportName)");

            List <IEdmOperationImport> operationImports;
            IEdmOperationImport        operationImport = null;

            if (this.operationImportCache.TryGetValue(functionImportName, out operationImports))
            {
                operationImport = operationImports.Cast <MetadataProviderEdmOperationImport>().SingleOrDefault(f => f.ServiceOperation == serviceOperation);
            }

            if (operationImport == null)
            {
                MetadataProviderEdmOperation operation = null;

                if (serviceOperation.Kind == OperationKind.Action || serviceOperation.Method == XmlConstants.HttpMethodPost)
                {
                    operation = new MetadataProviderEdmAction(this.model, serviceOperation, this.Namespace);
                    if (serviceOperation.OperationParameterBindingKind == OperationParameterBindingKind.Never)
                    {
                        operationImport = new MetadataProviderEdmActionImport(this.model, this, (MetadataProviderEdmAction)operation);
                    }
                }
                else
                {
                    Debug.Assert(serviceOperation.Method == XmlConstants.HttpMethodGet, "Method should be a get");
                    operation = new MetadataProviderEdmFunction(this.model, serviceOperation, this.Namespace);
                    if (serviceOperation.OperationParameterBindingKind == OperationParameterBindingKind.Never)
                    {
                        operationImport = new MetadataProviderEdmFunctionImport(this.model, this, (MetadataProviderEdmFunction)operation);
                    }
                }

                if (operationImport != null)
                {
                    if (operationImports == null)
                    {
                        operationImports = new List <IEdmOperationImport>();
                        this.operationImportCache.Add(functionImportName, operationImports);
                    }

                    operationImports.Add(operationImport);
                }

                this.model.AddOperation(operation);
            }

            return(operationImport);
        }
        /// <summary>
        /// Add a function import to the entity container.
        /// </summary>
        /// <param name="serviceOperation">The service operation to add to the entity container.</param>
        /// <returns>The newly added or cached function import instance.</returns>
        internal IEdmOperationImport EnsureOperationImport(OperationWrapper serviceOperation)
        {
            Debug.Assert(serviceOperation != null, "serviceOperation != null");
            string functionImportName = serviceOperation.Name;
            Debug.Assert(!string.IsNullOrEmpty(functionImportName), "!string.IsNullOrEmpty(functionImportName)");

            List<IEdmOperationImport> operationImports;
            IEdmOperationImport operationImport = null;
            if (this.operationImportCache.TryGetValue(functionImportName, out operationImports))
            {
                operationImport = operationImports.Cast<MetadataProviderEdmOperationImport>().SingleOrDefault(f => f.ServiceOperation == serviceOperation);
            }

            if (operationImport == null)
            {
                MetadataProviderEdmOperation operation = null;

                if (serviceOperation.Kind == OperationKind.Action || serviceOperation.Method == XmlConstants.HttpMethodPost)
                {
                    operation = new MetadataProviderEdmAction(this.model, serviceOperation, this.Namespace);
                    if (serviceOperation.OperationParameterBindingKind == OperationParameterBindingKind.Never)
                    {
                        operationImport = new MetadataProviderEdmActionImport(this.model, this, (MetadataProviderEdmAction)operation);
                    }
                }
                else
                {
                    Debug.Assert(serviceOperation.Method == XmlConstants.HttpMethodGet, "Method should be a get");
                    operation = new MetadataProviderEdmFunction(this.model, serviceOperation, this.Namespace);
                    if (serviceOperation.OperationParameterBindingKind == OperationParameterBindingKind.Never)
                    {
                        operationImport = new MetadataProviderEdmFunctionImport(this.model, this, (MetadataProviderEdmFunction)operation);
                    }
                }

                if (operationImport != null)
                {
                    if (operationImports == null)
                    {
                        operationImports = new List<IEdmOperationImport>();
                        this.operationImportCache.Add(functionImportName, operationImports);
                    }

                    operationImports.Add(operationImport);
                }

                this.model.AddOperation(operation);
            }

            return operationImport;
        }