title: EF 6 Code First Stored Procedure - Read Only
body: <p>I have searched a few posts, but have come up short. I am using EF6 code first trying to get results from a stored procedure that is already setup in a database. My application is simple, it takes data from two different servers, performs some business logic, and then shows the user. I can use the <code>.edmx</code> file fine, which maps the function in the xml file. When I use Power Tools to show myself the XML file I do not see the function import from my code below so I am either missing a setup or I cannot use <code>ExecuteFunction()</code>.</p>
  
  <ol>
  <li><p>Can I use the <code>ExecuteFunction()</code> with code first? My stored procedure only returns records. The reason I have this setup is because the stored procedure feeds another application and we want to keep all the changes to the query in one place (SSMS). I realize I could use <code>ExecuteStoredQuery</code> / <code>ExecureStoredCommand</code>, but I wanted to stick to the convention if I were to use the <code>.edmx</code> model.</p></li>
  <li><p>If I can use <code>ExecuteFunction</code>, where and how do I configure my <code>DbContext</code> to recognize the stored procedure? With my setup below I receive the error </p></li>
  </ol>
  
  <blockquote>
    <p>The FunctionImport {0} could not be found in the container {1}</p>
  </blockquote>
  
  <p>Can I use Fluent API? Thanks.</p>
  
  <pre><code>    public class JobContext : DbContext
      {
          public JobContext()
              : base("name=JobContext")
          {
              // My context will only define a slice of the database
              Database.SetInitializer&lt;JobContext&gt;(null);
          }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              modelBuilder.ComplexType&lt;Job&gt;();
          }
  
          public virtual ObjectResult&lt;Job&gt; uspGetJobs(string startDate)
          {
              var startDateParameter = startDate != null ?
                  new ObjectParameter("startDate", startDate) :
                  new ObjectParameter("startDate", typeof(string));
  
              return ((IObjectContextAdapter)this).ObjectContext.&lt;Job&gt;("uspGetJobs", startDateParameter);
          }
      }
  </code></pre>