2

I am trying to call a user defined sql function in my linq statement using entity framework. The function is called GetXml, and takes 2 strings called "data" and "path" and returns a string. My Data Model is called XmlDataModel. I included the function definition in the edmx file as so:

    <Function Name="GetXml" ReturnType="varchar(max)"   Schema="dbo">
      <Parameter Name="path" Type="varchar(max)" Mode="In" />
      <Parameter Name="data" Type="varchar(max)" Mode="In" />
    </Function>

I have the following declaration of the method in my code:

    [EdmFunction("XmlDataModel.Store", "GetXml")]
    public string GetXml(string path, string data)
    {
        throw new NotSupportedException("This method can only be used in a LINQ-toEntities query");
    }

And the following linq statement:

var test = from e in this.ObjectContext.Events 
           where GetXml("a", "b") == "test" select e.EventSpecificData;

My problem is that when I attempt to view the result set, I get the following message:

The specified method 'System.String GetXml(System.String, System.String)' on the type 'RIAServicesLibrary1.Web.XmlDomainService' cannot be translated into a LINQ to Entities store expression because the instance over which it is invoked is not the ObjectContext over which the query in which it is used is evaluated.

It seems to be recognizing that I have the method defined, because when I take out the [EdmFunction] tag I get a different message. Any ideas?

1
  • Have you tried making the method static?
    – Pawel
    Feb 9, 2012 at 17:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.