title: How to call Stored Procedure in Entity Framework 6 (Code-First)?
body: <p>I am very new to Entity Framework 6 and I want to implement stored procedures in my project. I have a stored procedure as follows:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[insert_department]
      @Name [varchar](100)
  AS
  BEGIN
      INSERT [dbo].[Departments]([Name])
      VALUES (@Name)
  
      DECLARE @DeptId int
  
      SELECT @DeptId = [DeptId]
      FROM [dbo].[Departments]
      WHERE @@ROWCOUNT &gt; 0 AND [DeptId] = SCOPE_IDENTITY()
  
      SELECT t0.[DeptId]
      FROM [dbo].[Departments] AS t0
      WHERE @@ROWCOUNT &gt; 0 AND t0.[DeptId] = @DeptId
  END
  </code></pre>
  
  <p><code>Department</code> class:</p>
  
  <pre><code>public class Department
  {
      public int DepartmentId { get; set; }       
      public string Name { get; set; }
  }
  
  modelBuilder 
  .Entity&lt;Department&gt;() 
  .MapToStoredProcedures(s =&gt; 
  s.Update(u =&gt; u.HasName("modify_department") 
                 .Parameter(b =&gt; b.Department, "department_id") 
                 .Parameter(b =&gt; b.Name, "department_name")) 
   .Delete(d =&gt; d.HasName("delete_department") 
                 .Parameter(b =&gt; b.DepartmentId, "department_id")) 
   .Insert(i =&gt; i.HasName("insert_department") 
                 .Parameter(b =&gt; b.Name, "department_name")));
  
  protected void btnSave_Click(object sender, EventArgs e)
  {
      string department = txtDepartment.text.trim();
  
      // here I want to call the stored procedure to insert values
  }
  </code></pre>
  
  <p><strong>My problem is:</strong> how can I call the stored procedure and pass parameters into it?</p>