title: Calling Stored procedure EF6 & MVC from Inteface in the repository pattern EXAMPLE
body: <p>I am using MVC 5 and Entity Framework 6 Database First approach.</p>
  
  <p>I cannot find an example of calling a stored procedure in the interface and the return type is another problem as for example:</p>
  
  <p>My Select is as follows</p>
  
  <pre><code>Create Procedure pcdSELECTEMPLOYEE
  
  @Del bit
  
  AS
  
  SELECT * FROM EMPLOYEE WHERE @Del = EMPLOYEE.DEL
  
  GO
  </code></pre>
  
  <p>Del is a flag field used for deleting in the database for best practice.</p>
  
  <p>So, my get all or even get by ID involves this:</p>
  
  <p>I have from EF a [GET/SET class] for employee
  A context class that has the stored procedure </p>
  
  <p>I need help with IRepository.cs and Repository.cs calling the <code>Context.pcdSELECTEMPLOYEE</code> or <code>Context.pcdSELECTEMPLOYEEBYID</code> </p>
  
  <p>What objects do I set in the interphace for return types or anything?</p>
  
  <pre><code>public interface IRepository&lt;T&gt;
  {
      IQueryable&lt;T&gt; GetAll();
      // other CRUD methods here...
  } 
  </code></pre>
  
  <p>Please help this would be much appreciated</p>
  
  <p>Thanks</p>
  
  <p>Entity Framework creates the following 
   public virtual </p>
  
  <pre><code>ObjectResult&lt;pcdSelectStaffBID_Result&gt;pcdSelectStaffBID(Nullable&lt;int&gt; iD)
          {
              var iDParameter = iD.HasValue ?
                  new ObjectParameter("ID", iD) :
                  new ObjectParameter("ID", typeof(int));
  
              return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction&lt;pcdSelectStaffBID_Result&gt;("pcdSelectStaffBID", iDParameter);
          }
  </code></pre>