コード例 #1
0
        private ExplorerItem CreateFunctionExplorerItem(FunctionData func, List <FunctionArgumentInfo> paramTypes)
        {
            var paramExplorerItems = paramTypes.Select(x =>
            {
                var itemText = $"{x.Name} ({x.Type?.Name ?? $"unknown type: {x.DbTypeName}"})";
                return(new ExplorerItem(itemText, ExplorerItemKind.Parameter, ExplorerIcon.Parameter));
            }).ToList();

            var funcType = func.IsMultiValueReturn ? ExplorerIcon.TableFunction : ExplorerIcon.ScalarFunction;

            var explorerItem = new ExplorerItem(func.Name, ExplorerItemKind.QueryableObject, funcType)
            {
                IsEnumerable = true,
                Children     = paramExplorerItems
            };

            return(explorerItem);
        }
コード例 #2
0
        private FunctionReturnTypeInfo DetermineReturnType(FunctionData func)
        {
            var funcReturnTypeInfo = new FunctionReturnTypeInfo();

            var mappedReturnType = SqlHelper.MapDbTypeToType(func.ReturnType, null, false, false);

            if (mappedReturnType != null)
            {
                funcReturnTypeInfo.ElementType = mappedReturnType;

                if (func.IsMultiValueReturn)
                {
                    funcReturnTypeInfo.CollectionType = typeof(IEnumerable <>).MakeGenericType(mappedReturnType);
                }
            }

            if (mappedReturnType == null)
            {
                var userTypeName = cxInfo.GetTypeName(func.ReturnType);

                // ToDo | add schema support for functions
                mappedReturnType = moduleBuilder.GetType($"{nameSpace}.public.{userTypeName}");

                if (mappedReturnType != null)
                {
                    funcReturnTypeInfo.ExistsAsTable  = true;
                    funcReturnTypeInfo.ElementType    = mappedReturnType;
                    funcReturnTypeInfo.CollectionType = typeof(ITable <>).MakeGenericType(mappedReturnType);
                }
            }

            if (mappedReturnType == null)
            {
                mappedReturnType = typeof(ExpandoObject);
                funcReturnTypeInfo.ElementType    = mappedReturnType;
                funcReturnTypeInfo.CollectionType = typeof(IEnumerable <>).MakeGenericType(mappedReturnType);
            }

            return(funcReturnTypeInfo);
        }
      private FunctionReturnTypeInfo DetermineReturnType(FunctionData func)
      {
         var funcReturnTypeInfo = new FunctionReturnTypeInfo();

         var mappedReturnType = SqlHelper.MapDbTypeToType(func.ReturnType, null, false, false);

         if (mappedReturnType != null)
         {
            funcReturnTypeInfo.ElementType = mappedReturnType;

            if (func.IsMultiValueReturn)
            {
               funcReturnTypeInfo.CollectionType = typeof(IEnumerable<>).MakeGenericType(mappedReturnType);
            }
         }

         if (mappedReturnType == null)
         {
            var userTypeName = cxInfo.GetTypeName(func.ReturnType);
            mappedReturnType = moduleBuilder.GetType($"{nameSpace}.{userTypeName}");

            if (mappedReturnType != null)
            {
               funcReturnTypeInfo.ExistsAsTable = true;
               funcReturnTypeInfo.ElementType = mappedReturnType;
               funcReturnTypeInfo.CollectionType = typeof(ITable<>).MakeGenericType(mappedReturnType);
            }
         }

         if (mappedReturnType == null)
         {
            mappedReturnType = typeof(ExpandoObject);
            funcReturnTypeInfo.ElementType = mappedReturnType;
            funcReturnTypeInfo.CollectionType = typeof(IEnumerable<>).MakeGenericType(mappedReturnType);
         }

         return funcReturnTypeInfo;
      }
      private ExplorerItem CreateFunctionExplorerItem(FunctionData func, List<FunctionArgumentInfo> paramTypes)
      {
         var paramExplorerItems = paramTypes.Select(x =>
         {
            var itemText = $"{x.Name} ({x.Type?.Name ?? $"unknown type: {x.DbTypeName}"})";
            return new ExplorerItem(itemText, ExplorerItemKind.Parameter, ExplorerIcon.Parameter);
         }).ToList();

         var funcType = func.IsMultiValueReturn ? ExplorerIcon.TableFunction : ExplorerIcon.ScalarFunction;

         var explorerItem = new ExplorerItem(func.Name, ExplorerItemKind.QueryableObject, funcType)
         {
            IsEnumerable = true,
            Children = paramExplorerItems
         };

         return explorerItem;
      }
      private List<FunctionArgumentInfo> GetFunctionArgumentInfos(FunctionData func)
      {
         Dictionary<int, string> argumentTypes;

         if (func.ArgumentTypeOids.Any())
         {
            argumentTypes = connection.Query(SqlHelper.LoadSql("QueryTypeByOid.sql").Replace("@oids", string.Join(",", func.ArgumentTypeOids)))
               .ToDictionary(x => (int)x.oid, x => (string)x.typname);
         }
         else
         {
            argumentTypes = new Dictionary<int, string>();
         }

         var paramTypes = new List<FunctionArgumentInfo>();

         for (int i = 0; i < func.ArgumentCount; i++)
         {
            var argName = func.ArgumentNames?[i];
            var argType = argumentTypes[func.ArgumentTypeOids[i]];
            Type mappedArgType;

            if (!TryMapToExistingType(argType, out mappedArgType))
            {
               TryCreateUserDefinedType(argType, out mappedArgType);
            }

            paramTypes.Add(new FunctionArgumentInfo { Index = i, Name = argName, Type = mappedArgType, DbTypeName = argType});
         }

         return paramTypes;
      }