我越來越像上面標籤的錯誤,這將是在的參數類型「Edm.String」和「Edm.Int32」是不兼容此操作
返回查看(st.employees的地方。查找(ID));
以上地方而已,任何一個可以幫助我從這裏!和我的代碼是
namespace StartApp.Controllers
{
public class EmployController : Controller
{
StartEntities st = new StartEntities();
//List
public ActionResult List()
{
return View(st.employees.ToList());
}
//Details
public ActionResult Details(int id = 0)
{
return View(st.employees.Find(id));
}
//Create
public ActionResult Create()
{
return View();
}
[HttpPost,ValidateAntiForgeryToken]
public ActionResult Create(employee e)
{
using(st)
{
st.employees.Add(e);
try
{
st.SaveChanges();
}
catch
{
System.Diagnostics.Debug.WriteLine("Here is an error");
}
}
return RedirectToAction("List");
}
//edit
public ActionResult Edit(int id = 0)
{
return View(st.employees.Find(id));
}
[HttpPost,ValidateAntiForgeryToken]
public ActionResult Edit(employee e)
{
st.Entry(e).State = EntityState.Modified;
st.SaveChanges();
return RedirectToAction("List");
}
//Delete
public ActionResult Delete(int id = 0)
{
return View(st.employees.Find(id));
}
[HttpPost,ActionName("Delete")]
public ActionResult Delete_conf(int id)
{
employee emp = st.employees.Find(id);
st.employees.Remove(emp);
st.SaveChanges();
return RedirectToAction("List");
}
}
}
任何一個可以幫助我改正這個錯誤!當你的實體主鍵是A型的,你是傳遞一個變量,它是A型的不給Find
方法
看看'Employee'實體。 「Key」的類型是什麼? –
它只是主鍵 –
班級中的密鑰的數據類型是什麼。 (查看edmx中的字段屬性或代碼文件) –