Exemplo n.º 1
0
        private List<FunctionParameter> CreateFunctionReturnParameters(FunctionDescriptor functionDescriptor)
        {
            var returnParameters = new List<FunctionParameter>();

            EdmType returnEdmType = null;
            switch (functionDescriptor.StoreFunctionKind)
            {
                case StoreFunctionKind.TableValuedFunction:
                    Debug.Assert(functionDescriptor.ReturnTypes.Length == 1, "Expected only one returnType for composable functions");
                    returnEdmType =
                        CreateReturnRowType(functionDescriptor.ResultColumnName, functionDescriptor.ReturnTypes[0])
                            .GetCollectionType();
                    break;
                case StoreFunctionKind.ScalarUserDefinedFunction:
                    var returnPrimtiveType = functionDescriptor.ReturnTypes[0].BuiltInTypeKind == BuiltInTypeKind.EnumType
                        ? ((EnumType) functionDescriptor.ReturnTypes[0]).UnderlyingType
                        : functionDescriptor.ReturnTypes[0];
                    returnEdmType = GetStorePrimitiveType(returnPrimtiveType);
                    break;
            }

            if (returnEdmType != null)
            {
                returnParameters.Add(
                    FunctionParameter.Create(
                        "ReturnParam",
                        returnEdmType,
                        ParameterMode.ReturnValue));
            }

            return returnParameters;
        }
Exemplo n.º 2
0
        public EdmFunction Create(FunctionDescriptor functionDescriptor)
        {
            Debug.Assert(functionDescriptor != null, "functionDescriptor is null");

            if (_schema == null && functionDescriptor.DatabaseSchema == null)
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Database schema is not defined for function '{0}'. Either set a default database schema or use the DbFunctionEx attribute with non-null DatabaseSchema value.",
                        functionDescriptor.Name));
            }

            var functionPayload =
                new EdmFunctionPayload
                {
                    Parameters = functionDescriptor
                        .Parameters
                        .Select(
                            p => FunctionParameter.Create(
                                p.Name,
                                GetStorePrimitiveType(
                                    p.EdmType.BuiltInTypeKind == BuiltInTypeKind.EnumType
                                        ? ((EnumType)p.EdmType).UnderlyingType
                                        : p.EdmType),
                                p.IsOutParam
                                    ? ParameterMode.InOut
                                    : ParameterMode.In)).ToArray(),

                    ReturnParameters = CreateFunctionReturnParameters(functionDescriptor),
                    IsComposable = functionDescriptor.StoreFunctionKind != StoreFunctionKind.StoredProcedure,
                    Schema = functionDescriptor.DatabaseSchema ?? _schema,
                };

            return EdmFunction.Create(
                functionDescriptor.Name,
                _namespace,
                DataSpace.SSpace,
                functionPayload,
                null);
        }