title: Map scalar-valued SQL function to method
body: <p>Inside a <code>DbContext</code> class, I try to map a methood to a SQL scalar function.
  The only documentation I can find about this is here: <a href="https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-2.0#database-scalar-function-mapping" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-2.0#database-scalar-function-mapping</a></p>
  
  <p>Where can I find the full documentation about this? </p>
  
  <p>I tried something like this, but I always get the exception I throw inside that function. Can I get more details about what is wrong?</p>
  
  <pre><code>[DbFunction]
  public static double CalcAmount(int Company, string Item, double Quantity)
      =&gt; throw new Exception();
  </code></pre>
  
  <p>The name is the same as the SQL function. I also tried addding the schema and function name in the attribute and added the function with modelbuilder, but nothing works.</p>
  
  <p>Also the SQL permissions are not a problem. </p>
  
  <p>Is only the name important? Is double vs float a problem? (I tried both)</p>
  
  <p>Can I use the function anywhere? I tried using it in a LINQ query.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I used the function like this:</p>
  
  <pre><code>from t in ctx.MyTable 
  select new { t, amount=MyDbContext.CalcAmount(1, "123", 2)}
  </code></pre>
  
  <p>If instead I use it like this:</p>
  
  <pre><code>from t in ctx.MyTable 
  select new { t.Prop1, t.Prop2, amount=MyDbContext.CalcAmount(1, "123", 2)}
  </code></pre>
  
  <p>Then it works.
  See the comments of Ivan Stoev</p>