// <summary>
        // Generates function definition or returns a cached one.
        // Guarantees type match of declaration and generated parameters.
        // Guarantees return type match.
        // Throws internal error for functions without definition.
        // Passes thru exceptions occured during definition generation.
        // </summary>
        internal DbLambda GenerateFunctionDefinition(EdmFunction function)
        {
            Debug.Assert(function.IsModelDefinedFunction, "Function definition can be requested only for user-defined model functions.");
            if (!function.HasUserDefinedBody)
            {
                throw new InvalidOperationException(Strings.Cqt_UDF_FunctionHasNoDefinition(function.Identity));
            }

            DbLambda generatedDefinition;

            // Generate the body
            generatedDefinition = ExternalCalls.CompileFunctionDefinition(
                function.CommandTextAttribute,
                function.Parameters,
                this);

            // Ensure the result type of the generated definition matches the result type of the edm function (the declaration)
            if (!TypeSemantics.IsStructurallyEqual(function.ReturnParameter.TypeUsage, generatedDefinition.Body.ResultType))
            {
                throw new InvalidOperationException(
                          Strings.Cqt_UDF_FunctionDefinitionResultTypeMismatch(
                              function.ReturnParameter.TypeUsage.ToString(),
                              function.FullName,
                              generatedDefinition.Body.ResultType.ToString()));
            }

            Debug.Assert(generatedDefinition != null, "generatedDefinition != null");

            return(generatedDefinition);
        }
示例#2
0
 internal static bool IsStructurallyEqualOrPromotableTo(TypeUsage fromType, TypeUsage toType)
 {
     if (!TypeSemantics.IsStructurallyEqual(fromType, toType))
     {
         return(TypeSemantics.IsPromotableTo(fromType, toType));
     }
     return(true);
 }
示例#3
0
 internal static bool IsValidPolymorphicCast(TypeUsage fromType, TypeUsage toType)
 {
     if (!TypeSemantics.IsPolymorphicType(fromType) || !TypeSemantics.IsPolymorphicType(toType))
     {
         return(false);
     }
     if (!TypeSemantics.IsStructurallyEqual(fromType, toType) && !TypeSemantics.IsSubTypeOf(fromType, toType))
     {
         return(TypeSemantics.IsSubTypeOf(toType, fromType));
     }
     return(true);
 }
示例#4
0
        internal DbLambda GenerateFunctionDefinition(EdmFunction function)
        {
            if (!function.HasUserDefinedBody)
            {
                throw new InvalidOperationException(Strings.Cqt_UDF_FunctionHasNoDefinition((object)function.Identity));
            }
            DbLambda dbLambda = ExternalCalls.CompileFunctionDefinition(function.CommandTextAttribute, (IList <FunctionParameter>)function.Parameters, this);

            if (!TypeSemantics.IsStructurallyEqual(function.ReturnParameter.TypeUsage, dbLambda.Body.ResultType))
            {
                throw new InvalidOperationException(Strings.Cqt_UDF_FunctionDefinitionResultTypeMismatch((object)function.ReturnParameter.TypeUsage.ToString(), (object)function.FullName, (object)dbLambda.Body.ResultType.ToString()));
            }
            return(dbLambda);
        }