i getting error above tag @ place of
return view(st.employees.find(id));
above place ,can 1 me this! , code is
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 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"); } }
}
can 1 me rectify error!
this exception happens when entities primary key of type , passing variable not of type find
method.
from official documentation of find
method, may throw below exception
invalidoperationexception
thrown if types of key values not match types of key values entity type found.
make sure use same type variable when call find
method.
in code, passing integer variable find
method. error believe entity classes primary key not int type. may guid
type, in case, make sure passing valid guid value find
method.
you can open edmx file , see type of key , make sure pass same type find
method.
just right click on entity in edmx file , select properties.
Comments
Post a Comment