title: How can I map a stored procedure to EF 6.1.1 Code First or later?
body: <p>I have been using the following code to execute a stored procedure in my C# controllers. db is my EF database context.</p>
  
  <pre><code>var sql = @"dbo.sp_add_test  @CreatedBy,
                               @CreatedDate,
                               @TestId,
                               @TestStatusId";   
  List&lt;SqlParameter&gt; parameterList = new List&lt;SqlParameter&gt;();
  parameterList.Add(new SqlParameter("@CreatedBy", Int32.Parse(User.Identity.GetUserId()) ));
  parameterList.Add(new SqlParameter("@CreatedDate", DateTime.UtcNow));
  parameterList.Add(new SqlParameter("@TestId", testId));
  parameterList.Add(new SqlParameter("@TestStatusId", 3));
  SqlParameter[] parameters = parameterList.ToArray();
  
  
  var test = await db.Database.SqlQuery&lt;Test&gt;(sql, parameters).FirstOrDefaultAsync();
  </code></pre>
  
  <p>I've had suggestions "why don't you map your SP in the EF context?"  However when I did research on this I found it very unclear as to how to do this.  First of all I saw there's a nuget package out there:  </p>
  
  <p><a href="http://www.nuget.org/packages/EntityFramework.CodeFirstStoreFunctions/" rel="nofollow">http://www.nuget.org/packages/EntityFramework.CodeFirstStoreFunctions/</a></p>
  
  <p>But I am not clear. Is this the only way to do it or has something changed. I see posts on the internet and SO but it appears that things are changing very recently so I think these may now be out of date.</p>
  
  <p>Can someone tell me how it's now done for EF 6.1.1. Please note I am looking for the official way to do this using only Microsoft tools. Also note I am using Code First so I cannot use the edmx mapper etc. </p>