I have a SQL function which I want to use in a lambda expression using the Entity Framework. Let's assume the SQL server function is "fooFunction". I have mapped this function in the Conceptual Model of the EDMX as follows:
<Function Name="fooFunction" ReturnType="Edm.String">
<Parameter Name="param1" Type="Edm.Int32" />
<Parameter Name="param2" Type="Edm.String" />
<DefiningExpression>
dbo.fooFunction(param1, param2)
</DefiningExpression>
</Function>
I have a static class in which I have mapped this function to code as follows:
[EdmFunction("Model", "fooFunction")]
public static string fooFunction(int param1, string param2)
{
throw new NotImplementedException("Direct calls are not supported.");
}
However, when I try to call this method (on a Compiled Query), I get the "cannot be translated into a store expression" error:
CompiledQuery.Compile<...> .... .Where(fooFunction(0,"")=="value")
I've been scratching my head for a while but I just don't get it.
Can anybody help me out here? Thanks!
Edit: whoops, I had a typo in my EdmFunction-attribute (whitespace):
[EdmFunction("Model", " fooFunction")]
However, now I get the "fooFunction cannot be resolved into a valid type or function."-error.