示例#1
0
        /// <summary>
        /// Gets the function as specified by the function key.
        /// All parameters are assumed to be <see cref="ParameterMode.In"/>.
        /// </summary>
        /// <param name="functionName">Name of the function</param>
        /// <param name="parameterTypes">types of the parameters</param>
        /// <param name="ignoreCase">true for case-insensitive lookup</param>
        /// <param name="function">The function that needs to be returned</param>
        /// <returns> The function as specified in the function key or null</returns>
        /// <exception cref="System.ArgumentNullException">if functionName or parameterTypes argument is null</exception>
        /// <exception cref="System.ArgumentException">if no function is found with the given name or with given input parameters</exception>
        internal bool TryGetFunction(string functionName, TypeUsage[] parameterTypes, bool ignoreCase, out EdmFunction function)
        {
            EntityUtil.GenericCheckArgumentNull(functionName, "functionName");
            EntityUtil.GenericCheckArgumentNull(parameterTypes, "parameterTypes");
            string     functionIdentity = EdmFunction.BuildIdentity(functionName, parameterTypes);
            GlobalItem item             = null;

            function = null;
            if (TryGetValue(functionIdentity, ignoreCase, out item) && Helper.IsEdmFunction(item))
            {
                function = (EdmFunction)item;
                return(true);
            }
            return(false);
        }
示例#2
0
        internal static List <EdmSchemaError> LoadItems(DbProviderManifest manifest, IList <Schema> somSchemas,
                                                        ItemCollection itemCollection)
        {
            List <EdmSchemaError> errors = new List <EdmSchemaError>();
            // Convert the schema, if model schema, then we use the EDM provider manifest, otherwise use the
            // store provider manifest
            IEnumerable <GlobalItem> newGlobalItems            = LoadSomSchema(somSchemas, manifest, itemCollection);
            List <String>            tempCTypeFunctionIdentity = new List <string>();

            // No errors, so go ahead and add the types and make them readonly
            foreach (GlobalItem globalItem in newGlobalItems)
            {
                // If multiple function parameter and return types expressed in SSpace map to the same
                // CSpace type (e.g., SqlServer.decimal and SqlServer.numeric both map to Edm.Decimal),
                // we need to guard against attempts to insert duplicate functions into the collection.
                //
                if (globalItem.BuiltInTypeKind == BuiltInTypeKind.EdmFunction && globalItem.DataSpace == DataSpace.SSpace)
                {
                    EdmFunction function = (EdmFunction)globalItem;

                    StringBuilder sb = new StringBuilder();
                    EdmFunction.BuildIdentity(
                        sb,
                        function.FullName,
                        function.Parameters,
                        // convert function parameters to C-side types
                        (param) => MetadataHelper.ConvertStoreTypeUsageToEdmTypeUsage(param.TypeUsage),
                        (param) => param.Mode);
                    string cTypeFunctionIdentity = sb.ToString();

                    // Validate identity
                    if (tempCTypeFunctionIdentity.Contains(cTypeFunctionIdentity))
                    {
                        errors.Add(
                            new EdmSchemaError(
                                Strings.DuplicatedFunctionoverloads(function.FullName, cTypeFunctionIdentity.Substring(function.FullName.Length)).Trim() /*parameters*/,
                                (int)ErrorCode.DuplicatedFunctionoverloads,
                                EdmSchemaErrorSeverity.Error));
                        continue;
                    }

                    tempCTypeFunctionIdentity.Add(cTypeFunctionIdentity);
                }
                globalItem.SetReadOnly();
                itemCollection.AddInternal(globalItem);
            }
            return(errors);
        }
示例#3
0
        /// <summary>
        /// Builds function identity string in the form of "functionName (param1, param2, ... paramN)".
        /// </summary>
        internal override void BuildIdentity(StringBuilder builder)
        {
            // If we've already cached the identity, simply append it
            if (null != CacheIdentity)
            {
                builder.Append(CacheIdentity);
                return;
            }

            EdmFunction.BuildIdentity(
                builder,
                FullName,
                Parameters,
                (param) => param.TypeUsage,
                (param) => param.Mode);
        }