Shaul Behr
Shaul Behr

Reputation: 37993

Calling a user defined function in EF - what am I doing wrong?

I've declared a user defined function in SQL server. Following the instructions here I refreshed the function into my EDMX (using "Update model from database"), which resulted in:

    <Function Name="uf_GradeToGradeFlag" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" ReturnType="smallint">
      <Parameter Name="grade" Type="smallint" Mode="In" />
    </Function>

I then created a static method:

   [EdmFunction("SchoolManagement.BL", "uf_GradeToGradeFlag")]
    public static short GradeToGradeFlag(short grade)
    {
        throw new NotSupportedException("Direct calls are not supported.");
    }

Now, when I invoke this method in a Linq-to-Entities call, I get:

System.NotSupportedException: The specified method 'Int16 GradeToGradeFlag(Int16)' on the type 'MyDomain.ModelDefinedFunctions' cannot be translated into a LINQ to Entities store expression.

I suspect the problem is with that namespaceName parameter in the EdmFunctionAttribute constructor. But the documentation is very hazy. What exactly is a "namespace", when you're talking about a SQL function?

Upvotes: 2

Views: 1030

Answers (1)

Shaul Behr
Shaul Behr

Reputation: 37993

Found the answer here:

The first attribute argument is the store namespace - you can find this in your edmx xml file on the Schema element (look for Namespace).

Upvotes: 1

Related Questions