How to execute stored procedure from Entity Framework 6 (database first) and Npgsql?
<p>Is this a bug? </p>

<p>My components are:</p>

<ol>
<li>.NET 4.6.1</li>
<li>Entity Framework 6.0</li>
<li>Npgsql 3.0.5</li>
<li>PostgreSQL 9.5</li>
</ol>

<p>First, I created a table and stored procedure in PostgreSQL 9.5</p>

<pre><code>CREATE TABLE hello
(
  msg text
)
WITH (
  OIDS=FALSE
);
ALTER TABLE hello
  OWNER TO postgres;

CREATE OR REPLACE FUNCTION sayhello()
  RETURNS SETOF hello AS
$BODY$ 

select
 *
 from version()

  $BODY$
  LANGUAGE sql VOLATILE
  COST 100
  ROWS 1000;
ALTER FUNCTION sayhello()
  OWNER TO postgres;
</code></pre>

<p>Second, I went to the <code>.edmx</code> file (Entity Framework 6.0), choose "update from database", selected the new table "hello" and the new stored procedure, "sayhello".</p>

<p>The Model Browser now shows the new table entity and the imported function.</p>

<p>Third, add a new procedure to the WCF file:</p>

<pre><code>public string SayHello()
{
            using (var ctx = new chaosEntities())
            {
                var x = ctx.sayhello();
                return "Hello";
            }
}
</code></pre>

<p>Set the WCF Service as Startup project and Start Debugging.</p>

<p>The WCF Test Client comes up. Executing <code>SayHello()</code> from the WCF Service leads to:</p>

<pre><code>public virtual ObjectResult&lt;hello&gt; sayhello()
{
    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction&lt;hello&gt;("sayhello");
}
</code></pre>

<p>When this is executed, I get:</p>

<blockquote>
  <p>An exception of type 'System.Data.Entity.Core.EntityCommandCompilationException'
  occurred in EntityFramework.dll but was not handled in user code</p>
  
  <p>Additional information: An error occurred while preparing the command
  definition. See the inner exception for details.</p>
  
  <p>Inner Exception is: {"Value does not fall within the expected range."}</p>
</blockquote>

<p>As I have several hundred stored procedures, any help on how to fix this is most appreciated.</p>

<p>TIA</p>

<p>Note: I suspect the problem is with NpgsqlServices.TranslateCommandTree, but I'm only guessing.</p>