/// <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>
        /// Constructor.
        /// </summary>
        /// <param name="model">The model this instance belongs to.</param>
        /// <param name="container">The container this instance belongs to.</param>
        /// <param name="edmOperation">The edm operation underlying this function import.</param>
        /// <remarks>This constructor assumes that the entity set for this service operation has already be created.</remarks>
        protected internal MetadataProviderEdmOperationImport(
            MetadataProviderEdmModel model, 
            MetadataProviderEdmEntityContainer container,
            MetadataProviderEdmOperation edmOperation)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(container != null, "container != null");
            Debug.Assert(edmOperation != null, "edmOperation != null");

            this.container = container;
            this.model = model;
            this.edmOperation = edmOperation;

            // EntitySetPath=<path string>
            ResourceSetPathExpression resultSetPathExpression = edmOperation.ServiceOperation.ResultSetPathExpression;
            this.entitySetPath = resultSetPathExpression == null ? null : resultSetPathExpression.PathExpression;
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="model">The model this instance belongs to.</param>
        /// <param name="container">The container this instance belongs to.</param>
        /// <param name="edmOperation">The edm operation underlying this function import.</param>
        /// <remarks>This constructor assumes that the entity set for this service operation has already be created.</remarks>
        protected internal MetadataProviderEdmOperationImport(
            MetadataProviderEdmModel model,
            MetadataProviderEdmEntityContainer container,
            MetadataProviderEdmOperation edmOperation)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(container != null, "container != null");
            Debug.Assert(edmOperation != null, "edmOperation != null");

            this.container    = container;
            this.model        = model;
            this.edmOperation = edmOperation;

            // EntitySetPath=<path string>
            ResourceSetPathExpression resultSetPathExpression = edmOperation.ServiceOperation.ResultSetPathExpression;

            this.entitySetPath = resultSetPathExpression == null ? null : resultSetPathExpression.PathExpression;
        }
        /// <summary>
        /// Add the given service operation to the model.
        /// </summary>
        /// <param name="operation">The operation to add to the model.</param>
        internal void AddOperation(MetadataProviderEdmOperation operation)
        {
            Debug.Assert(operation != null, "operation != null");

            if (!this.operationWrapperOperationLookUp.ContainsKey(operation.ServiceOperation))
            {
                this.operationWrapperOperationLookUp.Add(operation.ServiceOperation, operation);
            }

            if (!this.operationsQualifiedNameCache.ContainsKey(operation.FullName()))
            {
                this.operationsQualifiedNameCache.Add(operation.FullName(), new List<MetadataProviderEdmOperation>(new MetadataProviderEdmOperation[] { operation }));
            }
            else
            {
                var list = this.operationsQualifiedNameCache[operation.FullName()];
                if (!list.Contains(operation))
                {
                    list.Add(operation);
                }
            }
        }