// <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); }
internal static bool IsStructurallyEqualOrPromotableTo(TypeUsage fromType, TypeUsage toType) { if (!TypeSemantics.IsStructurallyEqual(fromType, toType)) { return(TypeSemantics.IsPromotableTo(fromType, toType)); } return(true); }
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); }
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); }