title: How to use a Database-first registered DbFunction inside another context with Linq To Entities?
body: <p>I would provide an Oracle Database <strong>function</strong> (ie. RemoveDiacritics) in my low-layer C# package which is installed on multiple websites, to allow these applications to use my custom function inside their Linq To Entities queries. The goal is to provide a way to use this function as simple as possible with no need to update their own EDMX models.</p>
  <p>In order to provide this function to other applications, I have created an empty EDMX model, then I have added the RemoveDiacritics function in the store:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Function Name=&quot;REMOVEDIACRITICS&quot; Aggregate=&quot;false&quot; BuiltIn=&quot;true&quot; NiladicFunction=&quot;false&quot; IsComposable=&quot;true&quot; ParameterTypeSemantics=&quot;AllowImplicitConversion&quot; Schema=&quot;MP&quot; ReturnType=&quot;varchar2&quot;&gt;
      &lt;Parameter Name=&quot;INPUT&quot; Type=&quot;varchar2&quot; Mode=&quot;In&quot; /&gt;
  &lt;/Function&gt;
  </code></pre>
  <p>I also expose the following function extension:</p>
  <pre class="lang-cs prettyprint-override"><code>public static class DbTools
  {
      [DbFunction(&quot;ModelDbFunction.Store&quot;, &quot;REMOVEDIACRITICS&quot;)]
      public static string RemoveDiacritics(this string input)
      {
          throw new NotSupportedException(&quot;this function is not supported&quot;);
      }
  }
  </code></pre>
  <p>But I'm a bit lost: how to mix my DbFunction context with other website context to allow them to use this function?
  Is there an other approach (based on Database-first logic) to provide a database function, according to the following restrictions:</p>
  <ul>
  <li>We are using EntityFramework 6.X (.NET Framework 4.6) with a Database-first logic</li>
  <li>We would not update the websites EDMX</li>
  <li>We would not use only SQL queries (there is, unfortunately, no way to mix Linq-to-Entities and RawSQL queries)</li>
  <li>We would not execute the request before applying filters and clauses (for performance reasons)</li>
  </ul>
  <p><strong>EDIT:</strong> Another approach would be to find a way to bind dynamically a DbFunction on a context in the C# package side, making the RemoveDiacritics function usable inside the Linq query; but this doesn't seem really possible, as I didn't found any alternative to do this (still with database-first).</p>
  <p>Thanks for your help.</p>