Пример #1
0
        private static TSqlCreateFunctionStatement CreateFunction(
            SqlAssemblyInfo assemblyInfo,
            MethodInfo method,
            SqlFunctionAttribute info)
        {
            if (method.ReturnType == typeof(IEnumerable) && !(info.FillRowMethodName is null))
            {
                return(CreateTableValuedFunction(assemblyInfo, method, info));
            }

            return(new TSqlCreateFunctionStatement(
                       name:
                       TSqlObjectIdentifier.Create("foundry", method.Name),
                       parameters:
                       method.GetParameters()
                       .Select(parameter => new TSqlModuleParameter($"@{parameter.Name}", parameter.ParameterType)),
                       returns:
                       TSqlType.CreateFromType(method.ReturnType),
                       definition:
                       new TSqlClrMethodSpecifier(
                           assemblyInfo.Name,
                           method.DeclaringType.FullName,
                           method.Name
                           )
                       ));
        }
Пример #2
0
        private static TSqlCreateFunctionStatement CreateTableValuedFunction(
            SqlAssemblyInfo assemblyInfo,
            MethodInfo method,
            SqlFunctionAttribute info)
        {
            var fillMethod = method.DeclaringType.GetMethod(info.FillRowMethodName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            return(new TSqlCreateFunctionStatement(
                       name:
                       TSqlObjectIdentifier.Create("foundry", method.Name),
                       parameters:
                       method.GetParameters()
                       .Select(parameter => new TSqlModuleParameter($"@{parameter.Name}", parameter.ParameterType)),
                       returns:
                       new TSqlClrTableType(
                           fillMethod.GetParameters()
                           .Skip(1)
                           .Select(parameter => new TSqlClrTableTypeColumn(parameter.Name, parameter.ParameterType.GetElementType()))
                           ),
                       definition:
                       new TSqlClrMethodSpecifier(
                           assemblyInfo.Name,
                           method.DeclaringType.FullName,
                           method.Name
                           )
                       ));
        }
Пример #3
0
        private static TSqlCreateProcedureStatement CreateProcedure(
            SqlAssemblyInfo assemblyInfo,
            MethodInfo method,
            SqlProcedureAttribute info)
        {
            return(new TSqlCreateProcedureStatement(
                       name: TSqlObjectIdentifier.Create("foundry", method.Name),

                       parameters: method.GetParameters()
                       .Select(parameter => new TSqlModuleParameter($"@{parameter.Name}", parameter.ParameterType)),

                       definition: new TSqlClrMethodSpecifier(
                           assemblyInfo.Name,
                           method.DeclaringType.FullName,
                           method.Name
                           )
                       ));
        }