c# - access object properties after it was added to db -
i have create method add new employee object database, after employee added want go edit page able enter more details employee if wish.
the edit action method takes 1 parameter, employeeid, employeeid dynamically assigned database once object added employee table. how access id of newly added employee after _db.savechanges() within same action method?
here part of method looks like:
[httppost] [validateantiforgerytoken] public actionresult create(employee employee) { _db.employees.add(employee); _db.savechanges(); //access employee , gets id??? //var id = id??? return redirecttoaction("editemployeeviewmodel", new { id = id}); }
you use this:
employee.id
the employee
object synchronized changes make db
. hence, when add objects employees
, call savechanges
, objects saved db
, it's state updated, having id
of employee
.
specifically, stated here:
entity framework default follows each insert select scope_identity() when autogenerated ids used.
Comments
Post a Comment