title: How to execute oracle user defined function in EF6
body: <p>I have a user defined function generated in my edmx:</p>
  
  <pre><code>&lt;Schema Namespace="DealerMaintenance.Store" Provider="Oracle.ManagedDataAccess.Client" ProviderManifestToken="11.2" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl"&gt;
  
  
    &lt;Function Name="GET_NEXT_DEALER_KY" Aggregate="false" BuiltIn="false"
       NiladicFunction="false" IsComposable="true"
       ParameterTypeSemantics="AllowImplicitConversion" Schema="MY_SCHEMA"
       ReturnType="number" /&gt;
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>public partial class DealerContext : DbContext
  {
      [DbFunction("DealerMaintenance.Store", "GET_NEXT_DEALER_KY")]
      public int? GetNextDealerKy()
      {
          var lObjectContext = ((IObjectContextAdapter)this).ObjectContext;
          var output = lObjectContext.
                  CreateQuery&lt;int?&gt;("DealerMaintenance.Store.GET_NEXT_DEALER_KY")
              .Execute(MergeOption.NoTracking)
              .FirstOrDefault();
          return output;
      }
  }
  </code></pre>
  
  <p>called using:</p>
  
  <pre><code>using (var objectContext = new DealerContext())
  {
    var x = objectContext.GetNextDealerKy();
  }
  </code></pre>
  
  <p>and got:</p>
  
  <blockquote>
    <p>An exception of type 'System.Data.Entity.Core.EntitySqlException'
    occurred in EntityFramework.dll but was not handled in user code</p>
    
    <p>Additional information: 'DealerMaintenance.Store.GET_NEXT_DEALER_KY'
    could not be resolved in the current scope or context. Make sure that
    all referenced variables are in scope, that required schemas are
    loaded, and that namespaces are referenced correctly. Near member
    access expression, line 1, column 24.</p>
  </blockquote>
  
  <p>I also tried variations of:</p>
  
  <pre><code>        using (var objectContext = new DealerContext())
          {
              var queryText = "SELECT DealerMaintenance.Store.GET_NEXT_DEALER_KY() FROM dual";
              ObjectQuery&lt;int&gt; adQuery = ((IObjectContextAdapter)objectContext).ObjectContext.CreateQuery&lt;int&gt;(queryText);
              var x =  adQuery.First();
          }
  </code></pre>
  
  <p>and got:</p>
  
  <blockquote>
    <p>'dual' could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly.</p>
  </blockquote>