title: MVC 5 Entity Framework 6 Execute Stored Procedure
body: <p>I'm stuck.  I have an existing application with an extremely large database and extensive library of stored procedures and functions.  All I want to do is use a DbContext to execute a stored procedure and return a set of data or map to one of the entities in the context.  Is that something magical I haven't discovered on the net somewhere?  Someone, anyone, please help.  Here's what I've got so far (and it doesn't return anything, the result is -1):</p>
  
  <pre><code>var contacts = db.Database.ExecuteSqlCommand("Contact_Search @LastName, @FirstName",
      new SqlParameter("@LastName", GetDataValue(args.LastName)),
      new SqlParameter("@FirstName", GetDataValue(args.FirstName)));
  </code></pre>
  
  <p>Executing that returns -1.  I also tried something to the effect of this with no success:</p>
  
  <pre><code>DbRawSqlQuery&lt;Contact&gt; data = db.Database.SqlQuery&lt;Contact&gt;
                                     ("EXEC Contact_Search @LastName, @FirstName",
                                         GetDataValue(args.LastName), 
                                         GetDataValue(args.FirstName));
  </code></pre>
  
  <p>I understand that I could add an edmx and map to a stored procedure that way, but that is not the preferred method.  Again, our database contains nearly 450 million records and a library of almost 3,000 stored procedures and functions.  It would be a nightmare to maintain.  Am I even starting in the right direction?  Is Entity Framework the right choice?  </p>