Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL User-Defined Functions in Linq to Entities
    primarykey
    data
    text
    <p>I am trying to call a user defined sql function in my linq statement using entity framework. The function is called <code>GetXml</code>, and takes 2 strings called "data" and "path" and returns a string. My Data Model is called <code>XmlDataModel</code>. I included the function definition in the edmx file as so:</p> <pre><code> &lt;Function Name="GetXml" ReturnType="varchar(max)" Schema="dbo"&gt; &lt;Parameter Name="path" Type="varchar(max)" Mode="In" /&gt; &lt;Parameter Name="data" Type="varchar(max)" Mode="In" /&gt; &lt;/Function&gt; </code></pre> <p>I have the following declaration of the method in my code:</p> <pre><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"); } </code></pre> <p>And the following linq statement:</p> <pre><code>var test = from e in this.ObjectContext.Events where GetXml("a", "b") == "test" select e.EventSpecificData; </code></pre> <p>My problem is that when I attempt to view the result set, I get the following message:</p> <blockquote> <p>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.</p> </blockquote> <p>It seems to be recognizing that I have the method defined, because when I take out the <code>[EdmFunction]</code> tag I get a different message. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload