I get error Procedure or function spAddDepartment has too many arguments specified
How to solve it
Details
when insert data to table department using stored procedure spAddDepartment using fluent api in mvc5
I get error above
Table department
CREATE TABLE [dbo].[Departments]( [DepartmentID] [int] IDENTITY(1,1) NOT NULL, [DepartmentName] [nvarchar](50) NULL, [IsActive] [bit] NULL
spAddDepartment ALTER Procedure [dbo].[spAddDepartment] @DepartmentName nvarchar(50) as Begin Insert into Departments values(@DepartmentName,1) End
public partial class Department { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public Department() { Employees = new HashSet<Employee>(); } public int DepartmentID { get; set; } [StringLength(50)] public string DepartmentName { get; set; } public bool? IsActive { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection<Employee> Employees { get; set; } }
database context
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Department>() .MapToStoredProcedures(p => p.Insert(sp => sp.HasName("spAddDepartment").Parameter(pm => pm.DepartmentName, "DepartmentName"))); }
[HttpPost] public ActionResult Insert(Department depart) { depart.IsActive = true; hr.Departments.Add(depart); hr.SaveChanges(); return View(depart); }
view as following
<div class="form-horizontal"> <h4>Department</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.DepartmentName, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.DepartmentName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.DepartmentName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.IsActive, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> <div class="checkbox"> @Html.EditorFor(model => model.IsActive) @Html.ValidationMessageFor(model => model.IsActive, "", new { @class = "text-danger" }) </div> </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Create" class="btn btn-default" /> </div> </div> </div>