title: Use stored procedure with parameters in Entity Framework
body: <p>I'm using Entity Framework 6.1.3 and have used the database-first approach to let it generate the model files and the <code>.EDMX</code>. I also have the following stored procedure on SQL Server 2008 R2, which Entity Framework brought into the EDMX:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[FindEmployee] 
      @LastName nvarchar(50), 
      @employeeID nvarchar(50),
      @securityID nvarchar(50)
  AS
  BEGIN
      SET NOCOUNT ON;
  
      select * 
      from Employee
      where 
          (lastName = dbo.trim(@LastName) AND dbo.trim(@LastName) IS NOT NULL)
          OR  (employeeID = dbo.trim(@employeeID) AND dbo.trim(@employeeID) IS NOT NULL)
          OR  (securityID = dbo.trim(@securityID) AND dbo.trim(@securityID) IS NOT NULL)
      order by
          case when dbo.trim(@LastName) is not null then CONVERT(char(50), lastName) + CONVERT(char(50), firstName) 
                  when dbo.trim(@employeeID) is not null then employeeID 
                  when dbo.trim(@securityID) is not null then securityID
              end
  END
  </code></pre>
  
  <p>In a Windows WPF app, I let the user select the column to search on (<code>lastName</code>, <code>employeeID</code>, or <code>securityID</code>) from a combobox. The user provides a search value which will get plugged into that parameter in the call to the stored procedure. The stored procedure then returns a resultset from its <code>SELECT</code> which I'll use to populate a <code>DataGrid</code>.</p>
  
  <p>I'm trying to call the stored procedure in this code; Note that the <code>FindEmployee_Result</code> is an auto-generated class in the EDMX for the stored procedure:</p>
  
  <pre><code>public FindEmployee_Result SearchEmployees(string lastName, string employeeID, string securityID)
  {
      var results = new FindEmployee_Result();
  
      using (var ctx = new TestSelectionEntities())
      {
          results = ctx.FindEmployee(lastName,employeeID,securityID);
      }
  
      return results;
  }
  </code></pre>
  
  <p>This code blows up with this error:</p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'System.Data.Entity.Core.Objects.ObjectResult' to 'TestSelection.data.FindEmployee_Result'</p>
  </blockquote>
  
  <p>What am I missing? Thank you.</p>